From: Eli Bendersky Date: 2006-05-13T01:02:12+09:00 Subject: Re: Making sense of the various Ruby "eval"s ts wrote: >>>>>> "E" == Eli Bendersky writes: > > E> - Kernel#eval - > > it's the evil eval, forget it :-) Forget Kernel#eval or the string version of any #eval ? The first maybe, but the second is what allows code generation on-the-fly. > > E> - Object#instance_eval - > > E> Is obj.instance_eval("blah") exactly the same as eval("blah", obj) ? > > You can give only a Proc/Binding to the evil eval > > E> work ? Are the contents of the block just treated as a string ? > > no, the block is executed with self = object And in the string version, what is 'self' ? I'm struggling to fully understand the difference between the block and the string versions ? > > E> - Module#class_eval - > > > moulon% cat b.rb > #!/usr/bin/ruby > class A > end > OK I think I understand: instance_eval adds instance methods to a class, and class/module_eval adds class methods to a class. But also instance_eval can be called on any object, but class_eval can't (it can be called only on class / module objects). Correct ? -- Posted via http://www.ruby-forum.com/.