Skip to content

Instantly share code, notes, and snippets.

@jenny-codes
Created December 5, 2019 23:50
Show Gist options
  • Save jenny-codes/191ad6ab5a79199a3d57b0dadbd7170b to your computer and use it in GitHub Desktop.
Save jenny-codes/191ad6ab5a79199a3d57b0dadbd7170b to your computer and use it in GitHub Desktop.
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