Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Binding#eval

binding.eval(string [, filename [,lineno]]) → obj

Evaluates the Ruby expression(s) in string, in the binding’s context. If the optional filename and lineno parameters are present, they will be used when reporting syntax errors.

Example
def get_binding(param)
  binding
end
b = get_binding("hello")
b.eval("param")   #=> "hello"

Ruby version changes

  1. 3.0
See also #irb #local_variable_defined? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1