struct Chem::Metadata::Any

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(raw : ValueType) #

Creates a new Any instance by enclosing the given value.


[View source]
def self.new(arr : Array(Array)) #

Creates a new Any instance by enclosing the given value.


[View source]
def self.new(arr : Array) #

Creates a new Any instance by enclosing the given value.


[View source]

Instance Method Detail

def ==(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

[View source]
def ==(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

[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def as_a : Array(Any) #

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


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def as_a? : Array(Any) | Nil #

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


[View source]
def as_bool : Bool #

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


[View source]
def as_bool? : Bool | Nil #

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


[View source]
def as_f : Float64 #

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


[View source]
def as_f? : Float64 | Nil #

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


[View source]
def as_i : Int32 #

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


[View source]
def as_i? : Int32 | Nil #

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


[View source]
def as_s : String #

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


[View source]
def as_s? : String | Nil #

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


[View source]
def inspect(io : IO) : Nil #
Description copied from struct Struct

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)"

[View source]

Returns the enclosed value.


[View source]
def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]