# Singleton Methods

**URL:** <https://www.ruby-forum.com/t/singleton-methods/75591>\
**Category:** Ruby\
**Created:** [November 11, 2006, 4:44am UTC](https://www.ruby-forum.com/t/singleton-methods/75591 "2006-11-11T04:44:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sur\_max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47774/32.png) [@sur\_max](https://www.ruby-forum.com/u/sur_max)\
**Post date:** [November 11, 2006, 4:44am UTC](https://www.ruby-forum.com/t/singleton-methods/75591/1 "2006-11-11T04:44:23Z")

</div>

Could anyone explain what exactly we meant by a Singleton Method ?  
See if i am thinking it right…

class A  
end  
a = A.new  
a.instance\_eval \<\<-EOS  
def wishing\_hello  
puts “HELLO !!”  
end  
EOS

so, here wishing\_hello will be a singleton method ?

---

<div class="post-metadata">

**Author:** ![sur\_max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47774/32.png) [@sur\_max](https://www.ruby-forum.com/u/sur_max)\
**Post date:** [November 11, 2006, 4:58am UTC](https://www.ruby-forum.com/t/singleton-methods/75591/2 "2006-11-11T04:58:26Z")

</div>

Hi –

On Sat, 11 Nov 2006, sur max wrote:

> EOS
> 
> so, here wishing\_hello will be a singleton method ?

Yes. A singleton method is basically a method that belongs to one  
object only. Since methods actually “belong to” classes and modules,  
rather than objects in general, Ruby implements singleton methods by  
means of singleton classes. Each object has its own, dedicated class  
– its singleton class – where its singleton methods are stored.

You can gain direct access to an object’s singleton class like this:

class \<\< a # from your example  
def wishing\_goodbye  
puts “GOODBYE!!”  
end  
end

wishing\_goodbye is now defined as an instance method in the singleton  
class of a.

David

---

<div class="post-metadata">

**Author:** ![sur\_max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47774/32.png) [@sur\_max](https://www.ruby-forum.com/u/sur_max)\
**Post date:** [November 11, 2006, 5:24am UTC](https://www.ruby-forum.com/t/singleton-methods/75591/3 "2006-11-11T05:24:29Z")

</div>

Thanks David !!

---

<div class="post-metadata">

**Author:** ![sur\_max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e47774/32.png) [@sur\_max](https://www.ruby-forum.com/u/sur_max)\
**Post date:** [November 11, 2006, 11:00am UTC](https://www.ruby-forum.com/t/singleton-methods/75591/4 "2006-11-11T11:00:57Z")

</div>

:fr sur max [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# Could anyone explain what exactly we meant by a Singleton Method ?

# See if i am thinking it right…

fr ola bini’s blog  
[Ola Bini: Programming Language Synchronicity: The Ruby singleton class](http://ola-bini.blogspot.com/2006/09/ruby-singleton-class.html).

just in case you want to think ruby 🙂

kind regards -botp
