RosettaCodeData/Task/Runtime-evaluation-In-an-en.../Ruby/runtime-evaluation-in-an-en...

10 lines
184 B
Ruby

def bind_x_to_value(x)
binding
end
def eval_with_x(code, a, b)
eval(code, bind_x_to_value(b)) - eval(code, bind_x_to_value(a))
end
puts eval_with_x('2 ** x', 3, 5) # Prints "24"