I''m trying to extend AR with a method which needs to be available to
both the class and the instance.
I''ve tried a gajillion permutations based on examples. I can get the
method added to the Class, but not to instances.
This seems like a logical pattern to me, but it''s apparently incorect.
module SpiffyMethods
module MyMethods
def shared_method
return "Hello?"
end
end
def self.included(base)
base.extend ClassMethods # works
base.include InstanceMethods # fails
end
module ClassMethods
include MyMethods
end
module InstanceMethods
include MyMethods
end
end
Need a point in the right direction. Thx.
-- gw
--
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
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 this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday 15 October 2010, Greg Willits wrote:> I''m trying to extend AR with a method which needs to be available to > both the class and the instance. > > I''ve tried a gajillion permutations based on examples. I can get the > method added to the Class, but not to instances.module MyMethods def self.included(base) base.extend(self) end def shared_method "Hello?" end end Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Well, that was easy. :-P Thanks! -- gw -- 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 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.