Skip to content

Instantly share code, notes, and snippets.

@ahmetabdi
Created September 19, 2017 15:20
Show Gist options
  • Save ahmetabdi/d3c8f76ee095994aa5c2ee0802d59c85 to your computer and use it in GitHub Desktop.
Save ahmetabdi/d3c8f76ee095994aa5c2ee0802d59c85 to your computer and use it in GitHub Desktop.
def zero(method = nil)
calculate(method, 0)
end
def one(method = nil)
calculate(method, 1)
end
def two(method = nil)
calculate(method, 2)
end
def three(method = nil)
calculate(method, 3)
end
def four(method = nil)
calculate(method, 4)
end
def five(method = nil)
calculate(method, 5)
end
def six(method = nil)
calculate(method, 6)
end
def seven(method = nil)
calculate(method, 7)
end
def eight(method = nil)
calculate(method, 8)
end
def nine(method = nil)
calculate(method, 9)
end
def calculate(method, value)
method ? eval("#{value} #{method}") : value
end
def plus(value)
"+ #{value}"
end
def minus(value)
"- #{value}"
end
def times(value)
"* #{value}"
end
def divided_by(value)
"/ #{value}.to_f"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment