Class: Bool

Inherits:
DataType show all
Defined in:
lib/sdx/vm/datatypes.rb

Instance Attribute Summary

Attributes inherited from DataType

#fields, #internal

Instance Method Summary collapse

Constructor Details

#initialize(val = nil) ⇒ Bool

Returns a new instance of Bool.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sdx/vm/datatypes.rb', line 47

def initialize(val=nil)
    if val
        @internal = true
    else
        @internal = false
    end
    @fields = {
        "__as_string" => (NativeFn.new 0, (Proc.new do
            as_string
        end)),
        "__as_code_string" => (NativeFn.new 0, (Proc.new do
            as_string
        end)),
        "__eq" => (NativeFnInternal.new (lambda do |other|
            Bool.new @internal == other[0].internal
        end)),
        "__neq" => (NativeFnInternal.new (lambda do |other|
            Bool.new @internal != other[0].internal
        end))
    }
end

Instance Method Details

#as_stringObject



69
70
71
# File 'lib/sdx/vm/datatypes.rb', line 69

def as_string
    Str.new ({ true => "true", false => "false" }[@internal])
end