struct

UCL::Any

Inherits Struct < Value < Object

A thin, typed view over a decoded UCL::Value::Type, in the spirit of JSON::Any. Lets callers navigate and coerce values without manual casts:

cfg = UCL.load_any(File.read("app.conf"))
cfg["server"]["port"].as_i  # => 8080
cfg["server"]["hosts"].as_a # => [UCL::Any, ...]

Constructors

Instance methods

[](key : String) : Any

Returns the element for the object key, wrapped. Raises if the value is not an object or the key is missing.

Source
[](index : Int) : Any

Returns the element at array index, wrapped. Raises if not an array.

Source
[]?(key : String) : Any | Nil

Like #[](String) but returns nil when this is not an object or the key is absent.

Source
[]?(index : Int) : Any | Nil

Like #[](Int) but returns nil when this is not an array or the index is out of range.

Source
as_a

Returns the array elements, each wrapped in Any. Raises if not an array.

Source
as_bool

Coerces to Bool, raising TypeCastError on a mismatch.

Source
as_bool?

Coerces to Bool?, returning nil on a mismatch.

Source
as_f

Coerces to Float64, raising TypeCastError on a mismatch.

Source
as_f?

Coerces to Float64?, returning nil on a mismatch.

Source
as_h

Returns the object entries, each value wrapped in Any. Raises if not an object.

Source
as_i

Coerces to Int64, raising TypeCastError on a mismatch.

Source
as_i?

Coerces to Int64?, returning nil on a mismatch.

Source
as_s

Coerces to String, raising TypeCastError on a mismatch.

Source
as_s?

Coerces to String?, returning nil on a mismatch.

Source
raw

The wrapped decoded value.

Source
to_ucl(emit_type : String | UCL::Emitter = UCL::Encoder::DEFAULT_EMITTER) : String

Serializes the wrapped value to UCL/JSON/YAML/MsgPack. See UCL.dump.

Source