Class: Gobstones::Lang::Number
- Inherits:
-
Literal
show all
- Defined in:
- lib/gobstones/lang/literals/number.rb
Constant Summary
Constants inherited
from Literal
Literal::OPERATORS_MAPPING
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Literal
#<=>, #evaluate, #if_false, #if_true, #not, #same_type_as, #true?
Methods inherited from Expression
#evaluate, #is_function_call?
#equality_attributes
Constructor Details
#initialize(num) ⇒ Number
Returns a new instance of Number.
8
9
10
|
# File 'lib/gobstones/lang/literals/number.rb', line 8
def initialize(num)
@value = num
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
6
7
8
|
# File 'lib/gobstones/lang/literals/number.rb', line 6
def value
@value
end
|
Instance Method Details
#<(other) ⇒ Object
16
17
18
|
# File 'lib/gobstones/lang/literals/number.rb', line 16
def <(other)
value < other.value
end
|
#==(other) ⇒ Object
12
13
14
|
# File 'lib/gobstones/lang/literals/number.rb', line 12
def ==(other)
super(other) && value == other.value
end
|
#next ⇒ Object
38
39
40
|
# File 'lib/gobstones/lang/literals/number.rb', line 38
def next
self.class.new(value + 1)
end
|
#opposite ⇒ Object
30
31
32
|
# File 'lib/gobstones/lang/literals/number.rb', line 30
def opposite
self.class.new(-value)
end
|
#previous ⇒ Object
34
35
36
|
# File 'lib/gobstones/lang/literals/number.rb', line 34
def previous
self.class.new(value - 1)
end
|
#return_type ⇒ Object
20
21
22
|
# File 'lib/gobstones/lang/literals/number.rb', line 20
def return_type
:Number
end
|
#to_s ⇒ Object
42
43
44
|
# File 'lib/gobstones/lang/literals/number.rb', line 42
def to_s
"number #{value}"
end
|