wyrosdick wrote:>
> Why is that in so many plugins I see people using (including
> acts_as_taggable by DHH):
>
> # init.rb
> ActiveRecord::Base.send(:include, ActiveRecord::Acts::SomeModule)
>
> # lib/some_module.rb
> module ActiveRecord
> module Acts
> module SomeModule
> def self.included(base)
> base.extend(ClassMethods)
> end
>
> module ClassMethods
> def acts_as_something
> # code
> end
> end
> end
> end
> end
>
> why go through all that rather than just call:
>
> # init.rb
> ActiveRecord::Base.extend ActiveRecord::Acts::SomeModule::ClassMethods
>
> and skip the self.included method?
I guess the use of self.included paves the way for more complex things
to be done when the module included. It also allows the module to be
included into a single AR model or a class of AR models, rather than
into all of AR itself.
If you definitely want to apply the module to all of AR an even shorter
alternative is:
# lib/some_module.rb
class ActiveRecord
def self.acts_as_something
# code
end
end
--
We develop, watch us RoR, in numbers too big to ignore.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---