Skip to content

Instantly share code, notes, and snippets.

@divs1210 divs1210/ordered_infix.rb
Last active Dec 15, 2018

What would you like to do?
def ordered_infix(*nums_and_ops)
initial_val = nums_and_ops[0]
op_num_pairs = nums_and_ops.drop(1).each_slice(2).to_a
op_num_pairs.reduce(initial_val) do |accumulator, op_num_pair|
op, num = op_num_pair
accumulator.send(op, num)
ordered_infix 10, '/', 2, '-', 1, '*', 2
# => 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.