struct
Chem::Metadata::Any
- Chem::Metadata::Any
- Struct
- Value
- Object
Overview
Any wraps a value that can be any of the possible metadata
types (ValueType). It provides convenient #as_* cast methods.
Defined in:
chem/metadata.crConstructors
-
.new(raw : ValueType)
Creates a new
Anyinstance by enclosing the given value. -
.new(arr : Array(Array))
Creates a new
Anyinstance by enclosing the given value. -
.new(arr : Array)
Creates a new
Anyinstance by enclosing the given value.
Instance Method Summary
-
#==(rhs : self) : Bool
Returns
trueif the enclosed values are equal, elsefalse. -
#==(rhs) : Bool
Returns
trueif the enclosed value is equal to rhs, elsefalse. -
#as_2a(type : Int32.class) : Array(Array(Int32))
Returns the enclosed value as a nested array of Int32.
-
#as_2a(type : Float64.class) : Array(Array(Float64))
Returns the enclosed value as a nested array of Float64.
-
#as_2a(type : String.class) : Array(Array(String))
Returns the enclosed value as a nested array of String.
-
#as_2a(type : Bool.class) : Array(Array(Bool))
Returns the enclosed value as a nested array of Bool.
-
#as_2a?(type : Int32.class) : Array(Array(Int32)) | Nil
Returns the enclosed value as an nested array of Int32, or
nilif it's not an nested array of Int32. -
#as_2a?(type : Float64.class) : Array(Array(Float64)) | Nil
Returns the enclosed value as an nested array of Float64, or
nilif it's not an nested array of Float64. -
#as_2a?(type : String.class) : Array(Array(String)) | Nil
Returns the enclosed value as an nested array of String, or
nilif it's not an nested array of String. -
#as_2a?(type : Bool.class) : Array(Array(Bool)) | Nil
Returns the enclosed value as an nested array of Bool, or
nilif it's not an nested array of Bool. -
#as_a(type : Int32.class) : Array(Int32)
Returns the enclosed value as an array of Int32.
-
#as_a(type : Float64.class) : Array(Float64)
Returns the enclosed value as an array of Float64.
-
#as_a(type : String.class) : Array(String)
Returns the enclosed value as an array of String.
-
#as_a(type : Bool.class) : Array(Bool)
Returns the enclosed value as an array of Bool.
-
#as_a : Array(Any)
Returns the enclosed value as an array of
Any. -
#as_a?(type : Int32.class) : Array(Int32) | Nil
Returns the enclosed value as an array of Int32, or
nilif it's not an array of Int32. -
#as_a?(type : Float64.class) : Array(Float64) | Nil
Returns the enclosed value as an array of Float64, or
nilif it's not an array of Float64. -
#as_a?(type : String.class) : Array(String) | Nil
Returns the enclosed value as an array of String, or
nilif it's not an array of String. -
#as_a?(type : Bool.class) : Array(Bool) | Nil
Returns the enclosed value as an array of Bool, or
nilif it's not an array of Bool. -
#as_a? : Array(Any) | Nil
Returns the enclosed value as an array of
Any, ornilif it's not an array. -
#as_bool : Bool
Returns the enclosed value as a bool.
-
#as_bool? : Bool | Nil
Returns the enclosed value as a bool.
-
#as_f : Float64
Returns the enclosed value as a float.
-
#as_f? : Float64 | Nil
Returns the enclosed value as float.
-
#as_i : Int32
Returns the enclosed value as an integer.
-
#as_i? : Int32 | Nil
Returns the enclosed value as an integer.
-
#as_s : String
Returns the enclosed value as a string.
-
#as_s? : String | Nil
Returns the enclosed value as a string.
-
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#raw : ValueType | Array(ValueType) | Array(Array(ValueType))
Returns the enclosed value.
-
#to_s(io : IO) : Nil
Same as
#inspect(io).
Constructor Detail
Creates a new Any instance by enclosing the given value.
Creates a new Any instance by enclosing the given value.
Instance Method Detail
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
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
Returns the enclosed value as a nested array of Int32. Raises
TypeCastError if it's not a nested array of Int32.
Returns the enclosed value as a nested array of Float64. Raises
TypeCastError if it's not a nested array of Float64.
Returns the enclosed value as a nested array of String. Raises
TypeCastError if it's not a nested array of String.
Returns the enclosed value as a nested array of Bool. Raises
TypeCastError if it's not a nested array of Bool.
Returns the enclosed value as an nested array of Int32, or
nil if it's not an nested array of Int32.
Returns the enclosed value as an nested array of Float64, or
nil if it's not an nested array of Float64.
Returns the enclosed value as an nested array of String, or
nil if it's not an nested array of String.
Returns the enclosed value as an nested array of Bool, or
nil if it's not an nested array of Bool.
Returns the enclosed value as an array of Int32. Raises
TypeCastError if it's not an array of Int32.
Returns the enclosed value as an array of Float64. Raises
TypeCastError if it's not an array of Float64.
Returns the enclosed value as an array of String. Raises
TypeCastError if it's not an array of String.
Returns the enclosed value as an array of Bool. Raises
TypeCastError if it's not an array of Bool.
Returns the enclosed value as an array of Any. Raises
TypeCastError if it's not an array.
Returns the enclosed value as an array of Int32, or nil if
it's not an array of Int32.
Returns the enclosed value as an array of Float64, or nil if
it's not an array of Float64.
Returns the enclosed value as an array of String, or nil if
it's not an array of String.
Returns the enclosed value as an array of Bool, or nil if
it's not an array of Bool.
Returns the enclosed value as an array of Any, or nil if it's
not an array.
Returns the enclosed value as a float. Raises TypeCastError if
it's not a float.
Returns the enclosed value as an integer. Raises TypeCastError
if it's not an integer.
Returns the enclosed value as an integer. Returns nil if it's
not an integer.
Returns the enclosed value as a string. Raises TypeCastError if
it's not a string.
Returns the enclosed value as a string. Returns nil if it's not
a string.
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)"
Returns the enclosed value.