struct

Chem::Metadata::Any

Inherits Struct / Value / Object

Any wraps a value that can be any of the possible metadata types (ValueType). It provides convenient #as_* cast methods.

Constructors

new(raw : ValueType)

Creates a new Any instance by enclosing the given value.

Source
new(arr : Array(Array))

Creates a new Any instance by enclosing the given value.

Source
new(arr : Array)

Creates a new Any instance by enclosing the given value.

Source

Instance methods

==(rhs : self) : Bool

Returns true if the enclosed values are equal, else false.

Chem::Metadata::Any.new("123") == Chem::Metadata::Any.new("123") # => true
Chem::Metadata::Any.new("123") == Chem::Metadata::Any.new(123)   # => false
Source
==(rhs) : Bool

Returns true if the enclosed value is equal to rhs, else false.

Chem::Metadata::Any.new("123") == "123" # => true
Chem::Metadata::Any.new("123") == 123   # => false
Source
as_2a(type : Int32.class) : Array(Array(Int32))

Returns the enclosed value as a nested array of Int32. Raises TypeCastError if it's not a nested array of Int32.

Source
as_2a(type : Float64.class) : Array(Array(Float64))

Returns the enclosed value as a nested array of Float64. Raises TypeCastError if it's not a nested array of Float64.

Source
as_2a(type : String.class) : Array(Array(String))

Returns the enclosed value as a nested array of String. Raises TypeCastError if it's not a nested array of String.

Source
as_2a(type : Bool.class) : Array(Array(Bool))

Returns the enclosed value as a nested array of Bool. Raises TypeCastError if it's not a nested array of Bool.

Source
as_2a?(type : Int32.class) : Array(Array(Int32)) | Nil

Returns the enclosed value as an nested array of Int32, or nil if it's not an nested array of Int32.

Source
as_2a?(type : Float64.class) : Array(Array(Float64)) | Nil

Returns the enclosed value as an nested array of Float64, or nil if it's not an nested array of Float64.

Source
as_2a?(type : String.class) : Array(Array(String)) | Nil

Returns the enclosed value as an nested array of String, or nil if it's not an nested array of String.

Source
as_2a?(type : Bool.class) : Array(Array(Bool)) | Nil

Returns the enclosed value as an nested array of Bool, or nil if it's not an nested array of Bool.

Source
as_a(type : Int32.class) : Array(Int32)

Returns the enclosed value as an array of Int32. Raises TypeCastError if it's not an array of Int32.

Source
as_a(type : Float64.class) : Array(Float64)

Returns the enclosed value as an array of Float64. Raises TypeCastError if it's not an array of Float64.

Source
as_a(type : String.class) : Array(String)

Returns the enclosed value as an array of String. Raises TypeCastError if it's not an array of String.

Source
as_a(type : Bool.class) : Array(Bool)

Returns the enclosed value as an array of Bool. Raises TypeCastError if it's not an array of Bool.

Source
as_a

Returns the enclosed value as an array of Any. Raises TypeCastError if it's not an array.

Source
as_a?(type : Int32.class) : Array(Int32) | Nil

Returns the enclosed value as an array of Int32, or nil if it's not an array of Int32.

Source
as_a?(type : Float64.class) : Array(Float64) | Nil

Returns the enclosed value as an array of Float64, or nil if it's not an array of Float64.

Source
as_a?(type : String.class) : Array(String) | Nil

Returns the enclosed value as an array of String, or nil if it's not an array of String.

Source
as_a?(type : Bool.class) : Array(Bool) | Nil

Returns the enclosed value as an array of Bool, or nil if it's not an array of Bool.

Source
as_a?

Returns the enclosed value as an array of Any, or nil if it's not an array.

Source
as_bool

Returns the enclosed value as a bool. Raises TypeCastError if it's not a bool.

Source
as_bool?

Returns the enclosed value as a bool. Returns nil if it's not a bool.

Source
as_f

Returns the enclosed value as a float. Raises TypeCastError if it's not a float.

Source
as_f?

Returns the enclosed value as float. Returns nil if it's not a float.

Source
as_i

Returns the enclosed value as an integer. Raises TypeCastError if it's not an integer.

Source
as_i?

Returns the enclosed value as an integer. Returns nil if it's not an integer.

Source
as_s

Returns the enclosed value as a string. Raises TypeCastError if it's not a string.

Source
as_s?

Returns the enclosed value as a string. Returns nil if it's not a string.

Source
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 enclosed value.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source