[Rails] Re: modules
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.
On Sep 6, 11:46 am, John Merlino <stoici...@aol.com> wrote:
> thanks for response
>
> On Sep 6, 5:32 am, Frederick Cheung <frederick.che...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > On Thursday, September 6, 2012 2:39:00 AM UTC+1, John Merlino wrote:
>
> > > 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
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home