Hey all. So I managed to solve this fluid calculator problem but I’m not especially happy with the solution. I saw other solutions using `method_missing`

(e.g. the Calc2 class I include below) but I’m uneasy about `method_missing`

. Any suggestions for improvements here? Thanks in advance…

```
class Calc
attr_accessor :str
def initialize
self.str = ''
self
end
def plus
self.str << '+'
self
end
def minus
self.str << '-'
self
end
def times
self.str << '*'
self
end
def divided_by
self.str << '/'
self
end
%w(zero one two three four five six seven eight nine).each_with_index do |num, index|
define_method "#{num}" do
if self.str == ''
self.str << index.to_s
self
else
eval(self.str << index.to_s)
end
end
end
end
# nice n compact, but method_missing blech
class Calc2
def method_missing(method_name, *args)
@numbers ||= []
@numbers << { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, plus: "+", minus: "-", times: "*", divided_by: "/" }[method_name]
@numbers.size == 3 ? eval(@numbers.join) : self
end
end
require 'minitest/autorun'
class TestCalc < MiniTest::Unit::TestCase
def setup
@calc1 = Calc.new.four.plus.five
@calc2 = Calc.new.five.plus.four
@calc3 = Calc.new.six.divided_by.two
end
def test_1
assert_equal(9, @calc1)
end
def test_2
assert_equal(9, @calc2)
end
def test_3
assert_equal(3, @calc3)
end
end
```