struct
Rubellite::Value
- Rubellite::Value
- Struct
- Value
- Object
Overview
Represents a first-class Ruby value (equivalent to Ruby's C VALUE).
Provides transparent type checks, unboxing to Crystal primitives,
dynamic method dispatch, operator overloads, and block execution.
Defined in:
rubellite/convert.crrubellite/value.cr
Constructors
-
.from(obj) : Value
Converts a Crystal object to a Rubellite::Value
- .new(raw : LibRuby::Value)
Instance Method Summary
- #*(other) : Value
- #+(other) : Value
- #-(other) : Value
- #/(other) : Value
- #<(other) : Bool
- #<=(other) : Bool
- #==(other : Value) : Bool
-
#==(other) : Bool
Returns
trueif this struct is equal to other. - #>(other) : Bool
- #>=(other) : Bool
- #[](key) : Value
- #[]=(key, val) : Value
- #array? : Bool
-
#as_crystal
Auto-converts to Crystal primitive where possible
- #bool? : Bool
-
#call(method_name : String | Symbol, *args) : Value
Invokes a method on the Ruby object
-
#call_with_block(method_name : String | Symbol, *args, &block : Array(Value) -> Value) : Value
Invokes a method while passing a Crystal block as a Ruby block
- #class_name : String
- #false? : Bool
- #fixnum? : Bool
- #flonum? : Bool
- #hash? : Bool
-
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#inspect : String
Returns an unambiguous and information-rich string representation of this object, typically intended for developers.
- #numeric? : Bool
- #proc? : Bool
- #raw : LibRuby::Value
- #ruby_nil? : Bool
- #string? : Bool
- #symbol? : Bool
- #symbol_name : String
- #to_a : Array(Value)
-
#to_bool : Bool
Ruby truthiness: false and nil are falsey, everything else is truthy
- #to_f : Float64
- #to_f64 : Float64
- #to_h : Hash(Value, Value)
- #to_i : Int32
- #to_i32 : Int32
- #to_i64 : Int64
-
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#to_s : String
Returns a nicely readable and concise string representation of this object, typically intended for users.
- #to_sym : String
- #true? : Bool
Constructor Detail
Instance Method Detail
Returns true if this struct is equal to other.
Both structs' instance vars are compared to each other. Thus, two structs are considered equal if each of their instance variables are equal. Subclasses should override this method to provide specific equality semantics.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p2 = Point.new 1, 2
p3 = Point.new 3, 4
p1 == p2 # => true
p1 == p3 # => false
Invokes a method on the Ruby object
Invokes a method while passing a Crystal block as a Ruby block
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 an unambiguous and information-rich string representation of this object, typically intended for developers.
This method should usually not be overridden. It delegates to
#inspect(IO) which can be overridden for custom implementations.
Also see #to_s.
Ruby truthiness: false and nil are falsey, everything else is truthy