>>>>> "C" == Carlo Teubner <C.Teubner / t-online.de> writes:

C> Is there any difference between
C>   aModule.module_eval
C> and
C>   aModule.instance_eval

 With #module_eval, the code is evaluated with self = aModule and
 class = aModule 

 With #instance_eval, the code is evaluated with self = aModule and 
 class = singleton class of aModule

 You can see it with constants, a very stupid example

pigeon% cat b.rb
#!/usr/bin/ruby
class A
   def a
      puts CC
   end
   class << self
      def a
         puts CC
      end
   end
end

A.class_eval { CC = 12 }
A.instance_eval { CC = 24 }

A.new.a
A.a
pigeon% 

pigeon% b.rb
12
24
pigeon% 


Guy Decoux