From: Erik Veenstra Date: 2006-07-23T02:42:17+09:00 Subject: Re: *_eval > > There must be a difference. If I replace > > aModule.module_eval with aModule.instance_eval in one > > spcific situation, the results differ, although > > self.inspect returns the same value... > > Well, when you use keywords (like `def' 'alias') ruby use the > "current" class to know where it must define the method. > > With #instance_eval, the current class is the singleton class and ruby > will define singleton methods > > With #module_eval, the current is the class (i.e. self) and ruby define > instance methods. I never heard of this "current" before... Interesting... So, although the contexts look the same (self and object_id), in reality, they aren't... POLS? Well, _I_ am surprised! gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- class Foo instance_eval <<-END p [self, object_id] def bar1 end END module_eval <<-END p [self, object_id] def bar2 end END end p Foo.method_defined?(:bar1) p Foo.method_defined?(:bar2) p Foo.new.method(:bar1) rescue nil # No output! p Foo.new.method(:bar2) rescue nil ---------------------------------------------------------------- [Foo, -605293266] [Foo, -605293266] false true # ----------------------------------------------------------------