------ art_61665_8992445.1150144376767 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 6/12/06, uncutstone wu <uncutstone / sina.com> wrote: > > Please take a look at some exemplary code first. > > class MailTruck > instance_eval <<-EOS > define_method(:hello1) {puts "hello1"} > EOS > > define_method(:hello2) {puts "hello2"} > > instance_eval <<-EOS > def hello3 > puts "hello3" > end > EOS > > def hello4 > puts "hello4" > end > end > > hello1 and hello2 are instance methods. > hello3 is a class method. I am as surprised as you are and I could not find any hint in the documentation why it should be? instance_eval is an equivalent to self.instance_eval, I fail to see any reason why the method definition is evaluated as a class method. Can anyone explain while instance_eval without a receiver could change the context of self? Ty in advance Robert hello4 is a instance method. > > Why hello1 and hello2 are same, but hello3 and hello4 are different? > > It seems a little inconsistent . Somebody can give a clear explanation? > Thanks in advance. I agree Robert > uncutstone > > > > > > -- > Posted via http://www.ruby-forum.com/. > > -- Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------ art_61665_8992445.1150144376767--