Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Binding#eval

(::string src, ?::string filename, ?::int lineno) -> untyped
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.3 · 3.2 · 3.1 · 3.0