> So when you do this:
>
>    class Something
>      def self.greet
>        puts "Hello from #{self}!"
>      end
>    end
>
> you're defining a method on the object self -- which happens
> to be, at that point in execution, the class object
> Something.

And just to beat the horse a little more, that is equivalent to writing:

  class Something
    def Something.greet
      puts "Hello from #{self]"
    end
  end

In both cases you call the method on the class object itself (e.g., 
Something.greet).

I'm not sure whether there are subtle differences between those two idioms--it 
seems like the self.greet formulation is more common (at least in the rails 
world).  I think the other one is clearer, personally.

GHC Confidentiality Statement

This message and any attached files might contain confidential information 
protected by federal and state law. The information is intended only for the 
use of the individual(s) or entities originally named as addressees. The 
improper disclosure of such information may be subject to civil or criminal 
penalties. If this message reached you in error, please contact the sender and 
destroy this message. Disclosing, copying, forwarding, or distributing the 
information by unauthorized individuals or entities is strictly prohibited by 
law.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to