Metaprogramming with String Evaluations
class Numeric
[['add', '+'], ['subtract', '-'],
['multiply', '*',], ['divide', '/']].each do |method, operator|
define_method("#{method}_2") do
method(operator).call(2)
end
end
end
Related examples in the same category