Class: Gobstones::Lang::Literal

Inherits:
Expression show all
Includes:
Comparable
Defined in:
lib/gobstones/lang/literals/literal.rb

Direct Known Subclasses

Boolean, Color, Direction, Number

Constant Summary collapse

OPERATORS_MAPPING =
{
  equal: :==,
  not_equal: '!='.to_sym,
  less_than: :<,
  less_equal: :<=,
  greater_than: :>,
  greater_equal: :>=,
}.freeze

Instance Method Summary collapse

Methods inherited from Expression

#is_function_call?

Methods included from EqualityDefinition

#equality_attributes

Instance Method Details

#<(_other) ⇒ Object



31
32
33
# File 'lib/gobstones/lang/literals/literal.rb', line 31

def <(_other)
  subclass_responsibility
end

#<=>(other) ⇒ Object



24
25
26
27
28
29
# File 'lib/gobstones/lang/literals/literal.rb', line 24

def <=>(other)
  return 0 if self == other
  return -1 if self < other

  1
end

#==(other) ⇒ Object Also known as: eql?

TODO EqualityDefinition module seems to fail used with Comparable



18
19
20
# File 'lib/gobstones/lang/literals/literal.rb', line 18

def ==(other)
  self.class == other.class
end

#evaluate(_context) ⇒ Object



12
13
14
# File 'lib/gobstones/lang/literals/literal.rb', line 12

def evaluate(_context)
  self
end

#if_false(_block, _context) ⇒ Object



62
63
64
# File 'lib/gobstones/lang/literals/literal.rb', line 62

def if_false(_block, _context)
  not_boolean_type_error
end

#if_true(_block, _context) ⇒ Object



58
59
60
# File 'lib/gobstones/lang/literals/literal.rb', line 58

def if_true(_block, _context)
  not_boolean_type_error
end

#notObject



70
71
72
# File 'lib/gobstones/lang/literals/literal.rb', line 70

def not
  not_boolean_type_error
end

#return_typeObject



54
55
56
# File 'lib/gobstones/lang/literals/literal.rb', line 54

def return_type
  subclass_responsibility
end

#same_type_as(other) ⇒ Object



50
51
52
# File 'lib/gobstones/lang/literals/literal.rb', line 50

def same_type_as(other)
  return_type == other.return_type
end

#true?Boolean

Returns:



66
67
68
# File 'lib/gobstones/lang/literals/literal.rb', line 66

def true?
  not_boolean_type_error
end