Eval

From RubySpec

Jump to: navigation, search

Contents

Eval

The eval function lets one evaluate the expression inside a string. Here are some examples:

 eval("7+12") #evaluates to 19
 eval("Math.sin(30*Math::PI/180)") #gives 0.5

Be careful with eval in web applications(refer to Programming Ruby 2nd edition)

class_eval

instance_eval

module_eval

Personal tools