Re: extend keyword in class definition



Hi --

On Tue, 30 Sep 2008, Sebastian Hungerecker wrote:

ruud grosmann wrote:
Isn't a singleton method a method that applies to the
singleton class of one object?

It is a method that is defined on the singleton class of an object, yes.
As a singleton class by definition only has one instance that means that a
singleton method is a method that can be called on a single object and that
object only.

Although:

class C
end
class D < C
end

def C.x
end

D.x # subclass can call superclass's singleton methods

Technically, it's also true that if you extend an object with a
module, you're not really writing singleton methods, since the methods
in the module are available to other objects that use the module. The
singleton_method_added callback won't get called, for example.


David

--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!

.



Relevant Pages

  • Re: Support for singleton_class() (was Re: Call functions of superclass)
    ... I wish we could just go back to 'metaclass'. ... name for a singleton class which holds INSTANCE specific methods for a ... The fact that in the ruby implementation, ...
    (comp.lang.ruby)
  • Re: Every tile an object?!
    ... >> Then, instead of storing pointers to the singleton class, we can store ... You don't need to write save/load code for each tile ... a second lookup to get the visibility value. ...
    (rec.games.roguelike.development)
  • Re: solve this ruby problem
    ... Please don't get the above information about the 'Singleton Pattern' ... confuse your efforts to understand Ruby's very special use of the term ... Singleton Class, which is completely different. ... Everything in Ruby is a class, ...
    (comp.lang.ruby)
  • Re: Initializing Singletons
    ... Singleton class when the class used for initialization must also get ... abused patterns, BTW), you can try this: ... Daniel Pitts' Tech Blog: ...
    (comp.lang.java.programmer)
  • Re: define_method inside a module
    ... Try working in the singleton class: ... Intro to Ruby on Rails January 12-15 Fort Lauderdale, ...
    (comp.lang.ruby)