Skip to content

Instantly share code, notes, and snippets.

@mindplace
Last active March 21, 2016 00:04
Show Gist options
  • Select an option

  • Save mindplace/2f279d031a58999a9cb8 to your computer and use it in GitHub Desktop.

Select an option

Save mindplace/2f279d031a58999a9cb8 to your computer and use it in GitHub Desktop.
class Calculator
extend ExtraArrayMethods
def self.method_missing(method, *nums)
operators = {add: :+, subtract: :-, multiply: :*, divide: :/}
if operators.keys.include?(method)
nums.inject(operators[method])
else
"Sorry, '#{method.to_s}' method not available!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment