# How do the AR singleton methods actually do there magic?

**URL:** <https://www.ruby-forum.com/t/how-do-the-ar-singleton-methods-actually-do-there-magic/123923>\
**Category:** Rails\
**Created:** [December 22, 2007, 1:50am UTC](https://www.ruby-forum.com/t/how-do-the-ar-singleton-methods-actually-do-there-magic/123923 "2007-12-22T01:50:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [December 22, 2007, 1:50am UTC](https://www.ruby-forum.com/t/how-do-the-ar-singleton-methods-actually-do-there-magic/123923/1 "2007-12-22T01:50:31Z")

</div>

Hey all,

Ive been looking at the AR source code and wondering something. There is  
heavy use of (for example)

class Base  
class \<\< self  
#Â definitions  
end  
end

Now, I can see that this is how we get our nice syntax for model  
validations and so forth - but what I dont get is how that _actually_  
works behind the scences.

I found this post  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/57252](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/57252)  
detailing what that syntax means in detail, and I get that. But what  
confuses me, is how if the validations are class methods, are they  
validating instances of that class? What is actually going on behind the  
scenes?

If anyone can shed any light on this I would be very grateful

Cheers

Tim

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [December 22, 2007, 4:32am UTC](https://www.ruby-forum.com/t/how-do-the-ar-singleton-methods-actually-do-there-magic/123923/2 "2007-12-22T04:32:53Z")

</div>

Watch the MetaProgramming - Extending Ruby for Fun and Profit screencast  
by  
Dave T… [MetaProgramming - Extending Ruby for Fun and Profit](http://www.infoq.com/presentations/metaprogramming-ruby)

Check out my site [www.rubyplus.org](http://www.rubyplus.org), there is a screencast on Include Vs  
Extend that is also related.

On Dec 21, 2007 4:50 PM, Tim P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end  
> scenes?

–  
[http://www.rubyplus.org/](http://www.rubyplus.org/)  
Free Ruby Screencasts

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [December 22, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/how-do-the-ar-singleton-methods-actually-do-there-magic/123923/3 "2007-12-22T13:17:34Z")

</div>

Excellent resources - thanks Bala

Tim
