# how does table\_name static method work ?

**URL:** <https://discuss.rubyonrails.org/t/how-does-table-name-static-method-work/19910>\
**Category:** rubyonrails-talk\
**Created:** [October 31, 2007, 6:22pm UTC](https://discuss.rubyonrails.org/t/how-does-table-name-static-method-work/19910 "2007-10-31T18:22:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aktxyz](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@aktxyz](https://discuss.rubyonrails.org/u/aktxyz)\
**Post date:** [October 31, 2007, 6:22pm UTC](https://discuss.rubyonrails.org/t/how-does-table-name-static-method-work/19910/1 "2007-10-31T18:22:00Z")

</div>

There has to be a simple explanation for this.

I can do this to get the table name behind a model

> > User.table\_name

=\> "users"

Great. But looking at the table\_name code in active\_record/base.rb, the table\_name method is not static (no self.)!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def table\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reset\_table\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

So why can I call table\_name as a static method ???

---

<div class="post-metadata">

**Author:** ![Philip\_Hallstrom1](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Philip\_Hallstrom1](https://discuss.rubyonrails.org/u/Philip_Hallstrom1)\
**Post date:** [October 31, 2007, 8:58pm UTC](https://discuss.rubyonrails.org/t/how-does-table-name-static-method-work/19910/2 "2007-10-31T20:58:33Z")

</div>

> There has to be a simple explanation for this.
> 
> I can do this to get the table name behind a model
> 
> > > User.table\_name
> 
> =\> "users"
> 
> Great. But looking at the table\_name code in active\_record/base.rb, the table\_name method is not static (no self.)!
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def table\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reset\_table\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> So why can I call table\_name as a static method ???

Scroll up to around line 353 and you'll see this line:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class \<\< self # Class methods

So if you remove everything else you really have this:

module ActiveRecord &nbsp;&nbsp;&nbsp;class Base &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class \<\< self # Class methods &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def table\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.... &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;end end
