Ruby on Rails Wednesday, September 26, 2012

Methods attach themselves to whatever the current class is when they are
defined. If self is a class when the method is defined, then the method
becomes an instance method in that class. If self is not a class when
the method is defined, then the current class is self's class.


puts self
puts self.class

--output:--
main
Object


def do_stuff
end

self is the object called 'main', which ruby creates for you on startup,
and it is not a class, so do_stuff() attaches to self's class, which is
Object.

--
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@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.

No comments:

Post a Comment