uncle
1
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.)!
def table_name
reset_table_name
end
So why can I call table_name as a static method ???
uncle
2
def table_name
reset_table_name
end
So why can I call table_name as a static method ???
Scroll up to around line 353 and you’ll see this line:
class << self # Class methods
So if you remove everything else you really have this:
module ActiveRecord
class Base
class << self # Class methods
def table_name
…
end
end
end
end