Ruby : Eval , MetaProgramming, Misc
eval : evaluates a string as if it was code…
when create a class you open up a new scope …class Foo self is local variable in the scope end.
class_eval opens up the class..for adding methods to it…also this doesn’t start a new local scope….so all the global variables are available….basically what ever string/code is there executes in the local scope…it takes all the string code between do end block or a string….which gets evaluated….Also when the method gets added to the class “className” it will be available to within all class definition / between class end…This is equivalent to define_method on class KK ..end .the reciever is self here. so it is defined on the object of class..
instance_eval..code/string get executed on the object level or the scope of the object .to add new methods at the instance level .
just eval would just evaluate the code followed by the scope at which code needs to execute .This can be got by using the binding method / Binding object which contains the frozen variables….binding a simple statement on calling which the system documents the current variables and returns a Binding object which can be used with eval….
closure: is combination of binding + eval…….turned to into a object and can be called anytime….
send method in ruby is used to call the method on an object even though it is private…try using __send__ and the message to the whom and what parameters..
class << object usually open a new scope…..The previous variable are not available…