terminology: "class method" = "singleton method"?

P

petermichaux

I've seen references to singleton methods and class methods. They seem
to mean the same thing. True?

Thanks,
Peter
 
E

Eero Saynatkari

I've seen references to singleton methods and class methods. They seem
to mean the same thing. True?

Not entirely the same: a class method is a singleton method but a singleton
method is not always a class method in the traditional sense :)

A singleton method is just a method defined on a single object rather than
an entire class of objects. Because it so happens that classes are objects
too (class Class), methods can be defined on a Class object and since those
methods are invoked on the Class object itself they look like 'class methods'.

The syntax 'def self.class_method()' is in fact the exact same as the singleton
method syntax:

class Foo
end

f = Foo.new

def f.foo()
puts 'foo!'
end

f.foo

With class methods the receiving object is 'self', the class itself, rather than
some more conventional object like 'f' in the above example.

It might be useful to think of class instance methods (or class methods for
short) using this mental model:

f = Foo.new; f.instance_method

Versus

Foo = Class.new; Foo.class_method
Thanks,
Peter

E
 
T

Trans

Speaking of terminology and singleton class, I came across a new word
today, a word I had thought I knew but did'nt truly. And it fits the
definition of these classes perfectly. We all enjoy eigenclass, but
quite clearly these classes are *adhoc*.

T.
 
C

Christophe Grandsire

Selon Trans said:
Speaking of terminology and singleton class, I came across a new word
today, a word I had thought I knew but did'nt truly. And it fits the
definition of these classes perfectly. We all enjoy eigenclass, but
quite clearly these classes are *adhoc*.

Why would one want haddock classes when we have chunky bacon? ;)
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
G

Gavin Kistner

Speaking of terminology and singleton class, I came across a new word
today, a word I had thought I knew but did'nt truly. And it fits the
definition of these classes perfectly. We all enjoy eigenclass, but
quite clearly these classes are *adhoc*.

To be pedantic, it's "ad hoc", not "adhoc".

But...this is by far my favorite term for the class. :)
It describes that it's created on the fly.
It rather describes that it's specific to a certain item.
It has no geeky confusion of 'eigenclass'.
It has no conflict with existing programming terms like 'singleton'.

http://www.google.com/search?q=define:ad+hoc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top