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/typed_data.cr
rubellite/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_bool : Bool
-
#as_crystal
Auto-converts to Crystal primitive where possible
-
#as_crystal_deep : DeepValue
Recursive deep unboxer converting nested Arrays/Hashes into native Crystal collections
- #as_f : Float64
-
#as_i : Int32
Convenience unboxers
- #as_i64 : Int64
- #as_nil : Nil
- #as_s : String
-
#as_typed_data(type : T.class) : T forall T
Unwraps this Ruby Value into a Crystal TypedData instance of type T.
-
#as_typed_data?(type : T.class) : T | Nil forall T
Safely unwraps this Ruby Value into a Crystal TypedData instance, returning nil on type mismatch.
- #bool? : Bool
-
#call(method_name : String | Symbol, *args) : Value
Invokes a method on the Ruby object with protected execution
-
#call(method_name : String | Symbol, *args, &block : Array(Value) -> Value) : Value
Invokes a method with a block, delegating to call_with_block
-
#call?(method_name : String | Symbol, *args) : Value | Nil
Safe method dispatch: returns nil if an exception or NoMethodError occurs
-
#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 with protected execution
-
#call_with_kwargs(method_name : String | Symbol, *args, **kwargs) : Value
Invokes a method with positional arguments and keyword arguments using Ruby 3+ kwargs protocol
- #class_name : String
- #complex? : Bool
-
#dig(*keys) : Value | Nil
Safe nested key navigation across Hashes and Arrays (transparently handles String and Symbol keys)
-
#each(&block : Value -> Nil) : Nil
Iterates over each element in a Ruby Enumerable / Array
-
#each_pair(&block : Value, Value -> Nil) : Nil
Iterates over key-value pairs in a Ruby Hash
- #empty? : Bool
- #false? : Bool
- #fixnum? : Bool
- #float? : Bool
- #flonum? : Bool
- #has_key?(key) : 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.
- #integer? : Bool
- #keys : Array(Value)
-
#kind_of?(class_name : String) : Bool
Introspection: checks if the Ruby object is a kind of a Ruby class
- #length : Int32
- #numeric? : Bool
- #proc? : Bool
- #range? : Bool
- #rational? : Bool
- #raw : LibRuby::Value
- #regex? : Bool
-
#respond_to?(method_name : String | Symbol) : Bool
Introspection: checks if the Ruby object responds to a method
- #ruby_is_a?(class_name : String) : Bool
- #ruby_nil? : Bool
-
#send(method_name : String | Symbol, *args) : Value
Alias for call
- #set? : Bool
- #size : Int32
- #string? : Bool
- #symbol? : Bool
- #symbol_name : String
- #time? : Bool
-
#to_a(type : T.class) : Array(T) forall T
Typed unboxing for Arrays
- #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(k_type : K.class, v_type : V.class) : Hash(K, V) forall K, V
Typed unboxing for Hashes
- #to_h : Hash(Value, Value)
- #to_i : Int32
- #to_i32 : Int32
- #to_i64 : Int64
- #to_range : Range(Int64, Int64) | Nil
-
#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_set : Set(Value)
-
#to_slice : Bytes
Converts Ruby string (including embedded null bytes) to a native Crystal byte slice
- #to_sym : String
- #to_time : Time
- #true? : Bool
-
#typed_data?(type : T.class) : Bool forall T
Checks if this Ruby Value is a TypedData wrapping type T.
- #values : Array(Value)
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
Recursive deep unboxer converting nested Arrays/Hashes into native Crystal collections
Unwraps this Ruby Value into a Crystal TypedData instance of type T. Raises TypeException if the Value does not wrap type T.
Safely unwraps this Ruby Value into a Crystal TypedData instance, returning nil on type mismatch.
Invokes a method on the Ruby object with protected execution
Invokes a method with a block, delegating to call_with_block
Safe method dispatch: returns nil if an exception or NoMethodError occurs
Invokes a method while passing a Crystal block as a Ruby block with protected execution
Invokes a method with positional arguments and keyword arguments using Ruby 3+ kwargs protocol
Safe nested key navigation across Hashes and Arrays (transparently handles String and Symbol keys)
Iterates over each element in a Ruby Enumerable / Array
Iterates over key-value pairs in a Ruby Hash
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.
Introspection: checks if the Ruby object is a kind of a Ruby class
Introspection: checks if the Ruby object responds to a method
Ruby truthiness: false and nil are falsey, everything else is truthy
Typed unboxing for Hashes
Returns a nicely readable and concise string representation of this object, typically intended for users.
This method should usually not be overridden. It delegates to
#to_s(IO) which can be overridden for custom implementations.
Also see #inspect.
Converts Ruby string (including embedded null bytes) to a native Crystal byte slice
Checks if this Ruby Value is a TypedData wrapping type T.