struct Rubellite::Value

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.cr
rubellite/value.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from(obj) : Value #

Converts a Crystal object to a Rubellite::Value


[View source]
def self.new(raw : LibRuby::Value) #

[View source]

Instance Method Detail

def *(other) : Value #

[View source]
def +(other) : Value #

[View source]
def -(other) : Value #

[View source]
def /(other) : Value #

[View source]
def <(other) : Bool #

[View source]
def <=(other) : Bool #

[View source]
def ==(other : Value) : Bool #

[View source]
def ==(other) : Bool #
Description copied from struct Struct

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

[View source]
def >(other) : Bool #

[View source]
def >=(other) : Bool #

[View source]
def [](key) : Value #

[View source]
def []=(key, val) : Value #

[View source]
def array? : Bool #

[View source]
def as_crystal #

Auto-converts to Crystal primitive where possible


[View source]
def bool? : Bool #

[View source]
def call(method_name : String | Symbol, *args) : Value #

Invokes a method on the Ruby object


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


[View source]
def class_name : String #

[View source]
def false? : Bool #

[View source]
def fixnum? : Bool #

[View source]
def flonum? : Bool #

[View source]
def hash? : Bool #

[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]
def inspect : String #
Description copied from class Object

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.


[View source]
def numeric? : Bool #

[View source]
def proc? : Bool #

[View source]
def raw : LibRuby::Value #

[View source]
def ruby_nil? : Bool #

[View source]
def string? : Bool #

[View source]
def symbol? : Bool #

[View source]
def symbol_name : String #

[View source]
def to_a : Array(Value) #

[View source]
def to_bool : Bool #

Ruby truthiness: false and nil are falsey, everything else is truthy


[View source]
def to_f : Float64 #

[View source]
def to_f64 : Float64 #

[View source]
def to_h : Hash(Value, Value) #

[View source]
def to_i : Int32 #

[View source]
def to_i32 : Int32 #

[View source]
def to_i64 : Int64 #

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

Same as #inspect(io).


[View source]
def to_s : String #
Description copied from class Object

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.


[View source]
def to_sym : String #

[View source]
def true? : Bool #

[View source]