Створення замикань на основі параметрів :
class MathOperations
OPERATORS = {
add: '+',
subtract: '-',
multiply: '*',
divide: '/'
}
OPERATORS.each do |operation, operator|
define_method(operation) do |num1, num2|
eval("#{num1} #{operator} #{num2}")
end
end
end
math = MathOperations.new
puts math.add(5, 3)
puts math.multiply(4, 6)