Class: Str
Instance Attribute Summary
Attributes inherited from DataType
Instance Method Summary collapse
- #add(other) ⇒ Object
- #as_code_string ⇒ Object
- #as_string ⇒ Object
-
#initialize(val = nil) ⇒ Str
constructor
A new instance of Str.
- #mul(other) ⇒ Object
Constructor Details
#initialize(val = nil) ⇒ Str
Returns a new instance of Str.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/sdx/vm/datatypes.rb', line 249 def initialize(val=nil) if val != nil @internal = val end @fields = { "__as_str" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_str" => (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
283 284 285 286 287 288 289 290 291 |
# File 'lib/sdx/vm/datatypes.rb', line 283 def add(other) case other when Str else error "Cannot use Str + on #{other.class}" return nil end Str.new @internal + other.internal end |
#as_code_string ⇒ Object
279 280 281 |
# File 'lib/sdx/vm/datatypes.rb', line 279 def as_code_string (Str.new @internal.dump) end |