# Class \<\< self

**URL:** <https://www.ruby-forum.com/t/class-self/158186>\
**Category:** Ruby\
**Created:** [January 20, 2009, 10:02am UTC](https://www.ruby-forum.com/t/class-self/158186 "2009-01-20T10:02:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [January 20, 2009, 10:02am UTC](https://www.ruby-forum.com/t/class-self/158186/1 "2009-01-20T10:02:09Z")

</div>

Hi  
I have code like

class A  
class \<\<self  
def first  
-------  
end  
def second  
------  
end  
end  
end

```
What I understood is now the def first and second becomes class

```

methods of class A…Am I right? Is that its only use?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [January 20, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/class-self/158186/2 "2009-01-20T13:51:33Z")

</div>

Hi –

On Tue, 20 Jan 2009, Sijo Kg wrote:

> ```
> end
> end
> 
> ```
> 
> end
> 
> What I understood is now the def first and second becomes class  
> methods of class A…Am I right? Is that its only use?

class \<\< object puts you in a class definition block for the singleton  
class of object. Creating class methods is the most common use case,  
but it works on any object (other than a few built-ins that aren’t  
allowed to have singleton classes).

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Coming in 2009: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))

[http://www.wishsight.com](http://www.wishsight.com) =\> Independent, social wishlist management!
