I have the following:
module Thing def self.included(base) base.send :extend, ClassMethods end module ClassMethods attr_reader :things def has_things(*args) options = args.extract_options!
In another class that mixes in the Thing module:
class Group has_things :one, :two, :option => "something" end
When calling has_things inside the class, I would like to have the dynamic methods "foo_for_thing_one" and "foo_for_thing_two". For instance:
@group = Group.new @group.foo_for_thing_one
However, I get the following error:
`<module:InstanceMethods>': undefined method `things' for Module:Class (NoMethodError)
I understand that βselfβ in the problem line above (the first line of the InstanceMethods module) refers to the InstanceMethods module.
How can I refer to the method of the βthingsβ class (which returns [: one ,: two] in this example), so I can scroll through and create dynamic instance methods for each? Thank you If you have other suggestions for this, let me know.
ruby module ruby-on-rails mixins
robertwbradford
source share