Allen Young wrote:
> It seems that define_method doesn't work at all. I got many errors
> saying that there is no method defined for things like ferret_field1. I
> even tried to define a simple method dynamically with the following
> code at the class level of my model class.
>
> define_method :say_hello { puts 'hello' }
>
> But unexpectedly, method_missing is called, so it means that
> define_method doesn't work. Is there anything wrong about my using with
> define_method?
>
Well, I got something. If I write define_method is this way:
define_method(:say_hello) { puts 'hello' }
then the "say_hello" method can be defined dynamically. Quite strange!
But I still cannot figure out why
OtherClass.ferret_fields.keys.each do |field|
define_method :"ferret_#{field}" do
other_object.send(field)
end
end
doesn't work. Is this becouse define_method is in the context of
OtherClass and thus dynamically adds all the method to OtherClass?
allen
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk