Skip to content

Instantly share code, notes, and snippets.

@jenny-codes
Created December 5, 2019 23:50
Embed
What would you like to do?
an interface that allows basic calculations with strings
%i(one two three four five six seven eight nine ten).each_with_index do |num_literal, i|
define_method(num_literal) do |block = nil|
block ? block.call(i + 1) : i + 1
end
end
def plus(second)
lambda { |first| first + second }
end
def minus(second)
lambda { |first| first - second }
end
def times(second)
lambda { |first| first * second }
end
def devide(second)
lambda { |first| first / second }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment