eval

eval(string [, binding [, filename [,lineno]]]) รข obj
Instance Public methods

Evaluates the Ruby expression(s) in string. If binding is given, which must be a Binding object, the evaluation is performed in its context. If the optional filename and lineno parameters are present, they will be used when reporting syntax errors.

def get_binding(str)
  return binding
end
str = "hello"
eval "str + ' Fred'"                      #=> "hello Fred"
eval "str + ' Fred'", get_binding("bye")  #=> "bye Fred"
doc_ruby_on_rails
2015-04-17 09:57:06
Comments
Leave a Comment

Please login to continue.