On 7 Nov 2008, at 10:14, Max Williams wrote:
>
> I have some methods that i want to be able to call on any collection
> of
> ActiveRecord objects. What's the 'right' way to set this up? I don't
> want to just monkey patch Array as it's specific to an AR array.
If you extend AssociationCollection you'll be able to it on any
association (eg some_object.customers.foo). There is no proxy object
for the result of Foo.find though (I have an experimental plugin that
does do this). You could wrap the result of finds in a proxy (as i
did) or you could add singleton methods to the results of find
(ie
class << ActiveRecord::Base
def find_with_extra_methods(*args)
results = find_without_extra_methods(*args)
results.extend(SomeModuleOfExtraMethods) if results.is_a? Array
results
end
alias_method_chain :find, extra_methods
end
>
>
> Thanks
> max
> --
> Posted via http://www.ruby-forum.com/.
>
> >
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---