Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > terminology: "class method" = "singleton method"?

Reply
Thread Tools

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

 
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      11-07-2005
I've seen references to singleton methods and class methods. They seem
to mean the same thing. True?

Thanks,
Peter

 
Reply With Quote
 
 
 
 
Eero Saynatkari
Guest
Posts: n/a
 
      11-07-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

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



 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      11-07-2005
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.

 
Reply With Quote
 
Christophe Grandsire
Guest
Posts: n/a
 
      11-07-2005
Selon Trans <(E-Mail Removed)>:

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


 
Reply With Quote
 
Gavin Kistner
Guest
Posts: n/a
 
      11-07-2005
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*.


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%3Aad+hoc


 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      11-07-2005
Gavin Kistner <(E-Mail Removed)> wrote:

> It has no geeky confusion of 'eigenclass'.


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

martin
 
Reply With Quote
 
Trans
Guest
Posts: n/a
 
      11-07-2005
Actally it's just old-school geek --it's Latin

T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments