x
x
x


Do so in a way which:

 does not involve string manipulation of the input source code
 is plausibly extensible to a runtime-chosen set of bindings rather than just x
 does not make x a global variable


or note that these are impossible.



See also

 For more general examples and language-specific details, see Eval.
 Dynamic variable names is a similar task.


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"