view · edit · sidebar · attach · print · history

Using eval in Ruby

<< EOS | Index | LoadPath >>

s = "print 123"
eval(s)

returns

 123

Eval runs Ruby Code in Ruby code.

Calling Methods dynamically

Also be sure to use call more then eval because of the performance considerations.

 http://www.ruby-doc.org/docs/ProgrammingRuby/html/ospace.html#UC
view · edit · sidebar · attach · print · history
Page last modified on April 07, 2011, at 04:36 PM