lib/gobstones/lang/literals/number.rb in gobstones-0.0.2 vs lib/gobstones/lang/literals/number.rb in gobstones-0.0.3
- old
+ new
@@ -1,20 +1,17 @@
require 'gobstones/lang/literals/literal'
module Gobstones
-
module Lang
-
class Number < Literal
-
attr_reader :value
def initialize(num)
@value = num
end
- def == other
+ def ==(other)
super(other) && value == other.value
end
def <(other)
value < other.value
@@ -22,13 +19,13 @@
def return_type
:Number
end
- [:+, :-, :*, :/, :%, :**].each do |selector|
+ %i[+ - * / % **].each do |selector|
define_method selector do |other|
- self.class.new value.send(selector, other.value)
+ self.class.new(value.send(selector, other.value))
end
end
def opposite
self.class.new(-value)
@@ -40,10 +37,11 @@
def next
self.class.new(value + 1)
end
+ def to_s
+ "number #{value}"
+ end
end
-
end
-
end