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

10 lines
184 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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"