1 Dynamic Evaluate Code
Global method Eval compiles and executes a string containing a snippet of Ruby code, which is a very strong mechanism because it allows you to build the runtime
Code to execute. Look at the following example:
Ruby Code
Parameters = {}
Argf.each do |line|
name, expr = Line.split (/\s*=\s*/, 2)
parameters[name] = eval EX PR End
Suppose the output is like this:
Reference
A = 1
b = 2 + 3
c = ' Date '
Then your parameters should be like this {"A" =>1, "B" =>5, "C" => "Mon the CDT 21:17:47"}. But in that case, danger
She is very high, so if you pass in a "rm *" then it's depressing.
Ruby has three ways to do it at run time evaluate code, Class_eval, Module_eval, and Instance_eval, the first two are synonymous, and these three
A method actually does the same thing, they are all evaluate a string, or a block, but in doing this, they will
Self changes to their own recipients. If you want to see some examples, it is recommended that you look at Ruby's built-in library delegate.rb.
The Eval method can also invoke evaluate in the creation of local variables outside the surface.