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?
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/iUB3HFq0TPkJ. For more options, visit https://groups.google.com/groups/opt_out.
thanks for response On Sep 6, 5:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
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...-YDxpq3io04c@public.gmane.org>
wrote:> thanks for response
>
> On Sep 6, 5:32 am, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.