Last active
August 29, 2015 14:02
-
-
Save boxofrad/1a0b59a221b9433ba950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calc | |
NUMBERS = %w[one two three four five six seven eight nine ten] | |
def initialize(number = 0, meth = nil) | |
@number = number | |
@meth = meth | |
end | |
NUMBERS.each_with_index do |number, index| | |
define_method(number) do | |
value = index + 1 | |
if @meth | |
@number.send(@meth, value) | |
else | |
value | |
end | |
end | |
end | |
end | |
class Fixnum | |
OPS = { plus: :+, minus: :-, times: :*, divided_by: :/ } | |
OPS.each do |op, meth| | |
define_method(op) { Calc.new(self, meth) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment