Re: [Rails] Re: why we are Using self.method_name?
On Wed, Nov 28, 2012 at 6:46 AM, thil <thil.1212@gmail.com> wrote:
> Self.methods is static methods using the class name itself you can call the
> methods and is not available to the instance of the class.
There is no such thing as static methods in Ruby. self.method_name
(or sometimes self.class.method_name) are instance methods on the
singleton instance of the object (in 1.9 you can access the singleton
via singleton_class too). Since everything is an object in Ruby
(literally) you have multiple types of instances, in his case he is
accessing instance methods on the singleton (or anonymous class or
eigen, however you want to label it) vs instance methods on /an/
instance of that object.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home