From: Logan Capaldo Date: 2006-06-12T13:19:23+09:00 Subject: Re: Something inconsistent in ruby syntax?? On Jun 11, 2006, at 11:10 PM, uncutstone wu wrote: > hello1 and hello2 are instance methods. > hello3 is a class method. > 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. > > uncutstone hello1, hello2, and hello4 are all equivalent. They are the same thing as writing class A def hello1 ... end def hello2 ... end def hello4 ... end end For hello3 you've done the equivalent of class A def self.hello3 ... end end The reason doesn't happen with hello1 is instance_eval { # self is MailTruck in this block define_method(...) { ... } # this is like self.define_method(...) { ... } # since define_method is a method, # which is the same as define_method outside of the instance_eval in this case