Terminology: "class method" = "singleton method"?

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

Thanks,
Peter

petermichaux@yahoo.com wrote:

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 :slight_smile:

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

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.

Selon Trans <transfire@gmail.com>:

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? :wink:

···

--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.

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

But...this is by far my favorite term for the class. :slight_smile:
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%3Aad+hoc

···

On Nov 6, 2005, at 9:42 PM, Trans wrote:

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

+1

"Trans" <transfire@gmail.com> wrote in message
news:1131338352.807669.134120@g43g2000cwa.googlegroups.com...

···

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.

'Tis a sad day when *programmers* shy away from geekiness :slight_smile:

martin

···

Gavin Kistner <gavin@refinery.com> wrote:

It has no geeky confusion of 'eigenclass'.

Actally it's just old-school geek --it's Latin :wink:

T.