This is probably more of a Ruby question than a Rails question. I’ve
always wondered exactly how controller instance variables are being made
accessible to the ERb code in the views.
In the Agile Rails book on pages 38, there’s a sidebar at the top that
hints at what’s going on:
“Rails does some Ruby magic so that the instance variables of the
controller object are injected into the tmeplate object”.
and then on the next page, this sentence appears as part of the “story
- Rails processes this template through ERb… substituting in values
set up by the controller.
I’m really interested in learning what Ruby language features made this
cool stuff possible. In general, how can I get one object to “know
about” or get references to private attributes of another object?