struct

Oyl::Any

Inherits Struct < Value < Object

Oyl::Any is a convenient wrapper around all possible YAML values (Oyl::Any::Type) and can be used for traversing dynamic or unknown YAML structures.

require "oyl"

data = Oyl.parse("---\nname: oyl\nversion: 0.1.0")
data["name"].as_s    # => "oyl"
data["version"].as_s # => "0.1.0"

Constructors

Creates a Oyl::Any from a Oyl::Nodes::Node, typing scalars with the context's dialect. A << key stays a key: Oyl.parse has the parser apply merges.

Source
new(raw : Type)

Creates a Oyl::Any that wraps the given value.

Source

Instance methods

==(other : self)
[](index : Int) : Oyl::Any

Assumes the underlying value is an Array and returns the element at the given index.

Source
[](key : String) : Oyl::Any

Assumes the underlying value is a Hash and returns the value for the given key.

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

Returns the element at the given index, or nil.

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

Returns the value for the given key, or nil.

Source
as_a

Checks that the underlying value is Array, and returns it.

Source
as_a?

Checks that the underlying value is Array, and returns it. Returns nil otherwise.

Source
as_bool

Checks that the underlying value is Bool, and returns its value.

Source
as_bool?

Checks that the underlying value is Bool, and returns its value. Returns nil otherwise.

Source
as_bytes

Checks that the underlying value is Bytes, and returns it.

Source
as_bytes?

Checks that the underlying value is Bytes, and returns it. Returns nil otherwise.

Source
as_f

Checks that the underlying value is Float64, and returns its value.

Source
as_f32

Checks that the underlying value is Float64, and returns its value as Float32.

Source
as_f32?

Checks that the underlying value is Float64, and returns its value as Float32. Returns nil otherwise.

Source
as_f?

Checks that the underlying value is Float64, and returns its value. Returns nil otherwise.

Source
as_h

Checks that the underlying value is Hash, and returns it.

Source
as_h?

Checks that the underlying value is Hash, and returns it. Returns nil otherwise.

Source
as_i

Checks that the underlying value is Int64, and returns its value.

Source
as_i64

Checks that the underlying value is Int64, and returns its value.

Source
as_i64?

Checks that the underlying value is Int64, and returns its value. Returns nil otherwise.

Source
as_i?

Checks that the underlying value is Int64, and returns its value as Int32. Returns nil otherwise.

Source
as_nil

Checks that the underlying value is Nil, and returns nil.

Source
as_s

Checks that the underlying value is String, and returns its value.

Source
as_s?

Checks that the underlying value is String, and returns its value. Returns nil otherwise.

Source
as_time

Checks that the underlying value is Time, and returns its value.

Source
as_time?

Checks that the underlying value is Time, and returns its value. Returns nil otherwise.

Source
as_u64

Checks that the underlying value is UInt64, and returns its value. Only integers above Int64::MAX are read as one.

Source
as_u64?

Checks that the underlying value is UInt64, and returns its value. Returns nil otherwise.

Source
clone

Returns a new Oyl::Any with the raw value cloneed.

Source
dig(index_or_key) : Oyl::Any

Traverses the depth of a structure and returns the value, otherwise raises.

Source
dig(index_or_key, *subkeys) : Oyl::Any

Traverses the depth of a structure and returns the value, otherwise raises.

Source
dig?(index_or_key) : Oyl::Any | Nil

Traverses the depth of a structure and returns the value, or nil.

Source
dig?(index_or_key, *subkeys) : Oyl::Any | Nil

Traverses the depth of a structure and returns the value, or nil.

Source
dup

Returns a new Oyl::Any with the raw value duped.

Source
hash(hasher)

See Object#hash(hasher)

inspect(io : IO) : Nil

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Source
raw

Returns the raw underlying value.

Source
size

Returns the size of the underlying Array or Hash.

Source
to_oyl(builder : Oyl::Builder) : Nil

Writes this value with builder (see Oyl::Builder#write).

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
to_yaml(io : IO, *, style : Oyl::EmitStyle = :block, indent : Int32 = 2) : Nil

Writes this value as a YAML document (see Oyl.dump).

Source
to_yaml(*, style : Oyl::EmitStyle = :block, indent : Int32 = 2) : String

Writes this value as a YAML document (see Oyl.dump).

Source

Nested types