Class: Loxxy::Datatype::LXString

Inherits:
BuiltinDatatype show all
Defined in:
lib/loxxy/datatype/lx_string.rb

Overview

Class for representing a Lox string of characters value.

Instance Attribute Summary

Attributes inherited from BuiltinDatatype

#value

Instance Method Summary collapse

Methods inherited from BuiltinDatatype

#!, #!=, #accept, #and, #falsey?, #initialize, #or, #truthy?

Constructor Details

This class inherits a constructor from Loxxy::Datatype::BuiltinDatatype

Instance Method Details

#+(other) ⇒ Loxxy::Datatype::LXString

Perform the concatenation of two Lox stings or one Lox string and a Ruby String

Parameters:

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/loxxy/datatype/lx_string.rb', line 28

def +(other)
  case other
  when LXString
    self.class.new(value + other.value)
  when Numeric
    self.class.new(value + other)
  else
    err_msg = "`+': #{other.class} can't be coerced into #{self.class} (TypeError)"
    raise TypeError, err_msg
  end
end

#==(other) ⇒ Datatype::Boolean

Check the equality of a Lox String with another Lox object.

Parameters:

  • other (Datatype::LxString, String, Object)

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'lib/loxxy/datatype/lx_string.rb', line 13

def ==(other)
  case other
  when LXString
    (value == other.value) ? True.instance : False.instance
  when String
    (value == other) ? True.instance : False.instance
  else
    False.instance
  end
end

#to_strString

Method called from Lox to obtain the text representation of the object.

Returns:

  • (String)


42
43
44
# File 'lib/loxxy/datatype/lx_string.rb', line 42

def to_str
  value
end