|
|
||
------------------------------------------------------------ Kernel#eval eval(string [, binding [, filename [,lineno]) => obj ------------------------------------------------------------------------ Evaluates the Ruby expression(s) in _string_. If _binding_ is given, the evaluation is performed in its context. The binding may be a Binding object or a Proc object. If the optional _filename_ and _lineno_ parameters are present, they will be used when reporting syntax errors. def getBinding(str) return binding end str = "hello" eval "str ' Fred'" #=> "hello Fred" eval "str ' Fred'", getBinding("bye") #=> "bye Fred"
Kernel#eval --- eval(expr[, binding[, fname[, lineno=1]) 文字列 expr を Ruby プログラムとして評価してその結果を返しま す。第2引数に Proc オブジェクトまたは Binding オブジェ クトを与えた場合、そのオブジェクトを生成したコンテキストで文字列を 評価します。binding も参照してください。 def foo a = 1 binding end eval("p a", foo) # => 1 fname と lineno が与えられた場合には、ファイル fname 行番号 lineno に文字列があるかのように コンパイルされ、スタックトレースの表示などを差し替えることが できます。