On 8 Oct 2008, at 11:11, Vidmantas Kabošis wrote:
>
> Frederick Cheung wrote:
>> I think you need to post more of your code.
>
> Sure:
>
> module MyModule
> def self.included(base)
> base.extend ClassMethods
> end
>
> module ClassMethods
> def money_is(field_name)
> write_inheritable_attribute :some_field, 'value'
> class_inheritable_reader :some_field
>
> self.send(:include, MyModule::InstanceMethods)
> end
> end
>
> module InstanceMethods
> define_method "#{self.some_field}" do
> # code
> end
> end
> end
OK. when the define_method runs, self is the module InstanceMethods.
At that point it hasn't even been included in anything so there is no
way to get the value of some_field.
I would just be doing this from the money_is method (or if you want to
keep the InstanceMethods module then from its included hook.
Fred
>
>
>> script/console
> Loading development environment (Rails 2.1.0)
> /home/vidmantas/projects/my_project/vendor/plugins/my_module/lib/
> my_module.rb:16:NoMethodError:
> undefined method `some_field' for MyModule::InstanceMethods:Module
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---