modules

module ActionView   module Helpers     module FormHelper       def form_for(foo, bar)          instantiate_builder(foo, bar)       end       def instantiate_builder(foo,bar)         self       end     end   end end

"self" in instantiate_builder refers to ActionView::Helpers::FormHelper. self it will have access to methods in ActionView::Helpers (its parent module), correct?

Not necessarily.

if you do

class Foo

include ActionView::Helpers::FormHelper

end

then

f = Foo.new

f.instantiate_builder

then self in instantiate_builder is f. Whether or not other modules in ActionView::Helpers have been included in Foo is not guaranteed (in the particular case of view helpers in views then all the other submodules of ActionView::Helpers would normally have been included)

Fred

thanks for response

There's another situation like this:

ActiveSupport.on_load(:action_view) do cattr_accessor(:default_form_builder) { ::ActionView::Helpers::FormBuilder } end

This is ActionView::Helpers::FormHelper. But I believe that self in the context of the block refers to ActionView, because on_load executes the block only after ActionView is loaded and then yields ActionView to the block so that default_form_builder will become a class method on ActionView, which returns the FormBuilder class object.