lib/code/object/string.rb in template-ruby-0.1.0 vs lib/code/object/string.rb in template-ruby-0.2.0
- old
+ new
@@ -1,30 +1,60 @@
-require "bigdecimal"
-
class Code
class Object
class String < ::Code::Object
attr_reader :raw
def initialize(string)
@raw = string
end
+ def call(**args)
+ operator = args.fetch(:operator, nil)
+ arguments = args.fetch(:arguments, [])
+
+ if operator == "to_function"
+ to_function(arguments)
+ elsif operator == "+"
+ plus(arguments)
+ elsif operator == "reverse"
+ reverse(arguments)
+ else
+ super
+ end
+ end
+
+ def succ
+ ::Code::Object::String.new(raw.succ)
+ end
+
+ def to_sym
+ raw.to_sym
+ end
+
def to_s
raw
end
def inspect
raw.inspect
end
- def ==(other)
- raw == other.raw
+ private
+
+ def to_function(arguments)
+ sig(arguments)
+ Code.evaluate("(_) => { _.#{raw} }")
end
- alias_method :eql?, :==
- def hash
- [self.class, raw].hash
+ def plus(arguments)
+ sig(arguments, ::Code::Object::String)
+ other = arguments.first.value
+ ::Code::Object::String.new(raw + other.raw)
+ end
+
+ def reverse(arguments)
+ sig(arguments)
+ ::Code::Object::String.new(raw.reverse)
end
end
end
end