struct
UCL::Any
- UCL::Any
- Struct
- Value
- Object
Overview
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, ...]
Defined in:
ucl/any.crConstructors
Instance Method Summary
-
#[](key : String) : Any
Returns the element for the object key, wrapped.
-
#[](index : Int) : Any
Returns the element at array index, wrapped.
-
#[]?(key : String) : Any | Nil
Like
#[](String)but returnsnilwhen this is not an object or the key is absent. -
#[]?(index : Int) : Any | Nil
Like
#[](Int)but returnsnilwhen this is not an array or the index is out of range. -
#as_a : Array(Any)
Returns the array elements, each wrapped in
Any. -
#as_bool : Bool
Coerces to
Bool, raisingTypeCastErroron a mismatch. -
#as_bool? : Bool | Nil
Coerces to
Bool?, returningnilon a mismatch. -
#as_f : Float64
Coerces to
Float64, raisingTypeCastErroron a mismatch. -
#as_f? : Float64 | Nil
Coerces to
Float64?, returningnilon a mismatch. -
#as_h : Hash(String, Any)
Returns the object entries, each value wrapped in
Any. -
#as_i : Int64
Coerces to
Int64, raisingTypeCastErroron a mismatch. -
#as_i? : Int64 | Nil
Coerces to
Int64?, returningnilon a mismatch. -
#as_s : String
Coerces to
String, raisingTypeCastErroron a mismatch. -
#as_s? : String | Nil
Coerces to
String?, returningnilon a mismatch. -
#raw : UCL::Value::Type
The wrapped decoded value.
-
#to_ucl(emit_type : String | UCL::Emitter = UCL::Encoder::DEFAULT_EMITTER) : String
Serializes the wrapped value to UCL/JSON/YAML/MsgPack.
Constructor Detail
Instance Method Detail
Returns the element for the object key, wrapped. Raises if the value is not an object or the key is missing.
Returns the element at array index, wrapped. Raises if not an array.
Like #[](String) but returns nil when this is not an object or the key
is absent.
Like #[](Int) but returns nil when this is not an array or the index is
out of range.
Returns the array elements, each wrapped in Any. Raises if not an array.
Returns the object entries, each value wrapped in Any. Raises if not an
object.
Serializes the wrapped value to UCL/JSON/YAML/MsgPack. See UCL.dump.