The ActionView module is declared several times in the Rails source:
rails/actionpack/lib/action_view/base.rb,rails/actionpack/lib/
action_view/buffers.rb,rails/actionpack/lib/action_view/digestor.rb,
rails/actionpack/lib/action_view/helpers/asset_tag_helpers/
asset_paths.rb, and the list goes on and on.
How is it able to be declared like this in multiple files without the
previous definition of it being overwritten?
The ActionView module is declared several times in the Rails source:
rails/actionpack/lib/action_view/base.rb,rails/actionpack/lib/
action_view/buffers.rb,rails/actionpack/lib/action_view/digestor.rb,
rails/actionpack/lib/action_view/helpers/asset_tag_helpers/
asset_paths.rb, and the list goes on and on.
How is it able to be declared like this in multiple files without the
previous definition of it being overwritten?
It is a basic feature of Ruby that you can re-open a class definition
and add or redefine methods.
It’s kind of
“metaprogramminghttp://en.wikipedia.org/wiki/metaprogrammingcreating
code at runtime that defines new methods. In fact, in a sense all Ruby
programming is metaprogramming, since even a class definition is not a
declaration as it is in Java but actually code that is executed at
runtime.
Given that this is true, you might wonder whether you can modify a
class
at runtime. In fact you can, by adding or changing instance methods or
class methods, even for Rubys built-in classes”.
This is citation from book Engineering Long-Lasting Software: An Agile
Approach Using SaaS and Cloud
Computinghttp://www.amazon.com/dp/B006WU5G4C