Class: Str

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) ⇒ Str



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/sdx/vm/datatypes.rb', line 178

def initialize(val=nil)
    if val != nil
        @internal = val
    end
    @fields = {
        "__as_string" => (NativeFnInternal.new (Proc.new do 
            as_string
        end)),
        "__as_code_string" => (NativeFnInternal.new (Proc.new do
            as_code_string
        end)),
        "__add" => (NativeFnInternal.new (Proc.new do |other|
            add other[0]
        end)),
        "__mul" => (NativeFnInternal.new (Proc.new do |other|
            mul other[0]
        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

#add(other) ⇒ Object



212
213
214
# File 'lib/sdx/vm/datatypes.rb', line 212

def add(other)
    Str.new @internal + other.internal
end

#as_code_stringObject



208
209
210
# File 'lib/sdx/vm/datatypes.rb', line 208

def as_code_string
    (Str.new @internal.dump)
end

#as_stringObject



204
205
206
# File 'lib/sdx/vm/datatypes.rb', line 204

def as_string
    (Str.new @internal)
end

#mul(other) ⇒ Object



216
217
218
# File 'lib/sdx/vm/datatypes.rb', line 216

def mul(other)
    Str.new @internal * other.internal
end