From: [email protected] [mailto:[email protected]]
But there’s still no: include ActionController::Layout::ClassMethods.
Nope. But in action_controller/layout.rb there is:
module ActionController #:nodoc:
module Layout #:nodoc:
def self.included(base)
base.extend(ClassMethods)
[…snip…]
end
end
end
HOW DO YOU KNOW, BOTTOM LINE, AFTER ALL THE VARIOUS FILES ARE
CONSIDERED, WHAT A CLASS DOES?
A few choices:
- At runtime, ask it:
C:.…\site>ruby script\console
Loading development environment.
puts ActionController::Base.methods.sort
<
<=
<=>
==
===
=~=
id
[…snip…]
layout
layout_conditions
load
[…snip…]
-
Trust the author(s) of the code to write sufficient documentation
that explains to you all you need to know. -
Read the source code.
I realize that none of these are ideal for huge projects like rails. I’m
not claiming that they are, I’m just laying out some options.
I still don’t know how ApplicationController::Base can call
layout(). I still can’t understand why it’s not in the doc as common
sense demands.
Hopefully you now understand why it can call layout. To recap:
ActionController::Base.class_eval do
include ActionController::Layout
end
…
module ActionController::Layout
def self.included(base)
base.extend(ClassMethods)
end
end
Why it’s not in the documentation is because:
- RDoc was not smart enough to figure out that the end result of all
those runtime calls would always include ClassMethods methods as methods
of the ActionController::Base class.
and - Nobody writing the documentation for rails noticed this omission and
wrote additional explanatory code letting you know that all the methods
from ActionController::Layout::ClassMethods are available inside
ActionController::Base.