Pardee, Roy
2008-Aug-20 15:22 UTC
Re: Difference in public class methods and instance methods?
"Public" refers to the accessibility of the methods--public methods can be called from anyplace. Compare private methods, which are only accessible from within the module where they are defined (or something close to that). Instance methods are called on (and operate on) particular well, instances of a class. In this code: x = "boogers" x.length # -> 7 The .length method on the String class is an instance method. We are asking *this particular instance* of String (which we have given the name ''x'') how many characters it has. Class methods are called on the class itself. For example, String.new is a class method--the class creates a new string and returns it. You couldn''t say x.new--x is just an instance of string. The only thing that can create new instances of String is the String class. In other languages these are often called ''static'' methods. For more detail, I recommend David Black''s _Ruby For Rails_, and/or the pickaxe book. HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Sunny Bogawat Sent: Wednesday, August 20, 2008 4:37 AM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Difference in public class methods and instance methods? What is difference between public class methods and public instance methods? I am interested in knowing in detail way. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---