On Mon, May 14, 2007 at 01:42:26PM +0200, Allen Young wrote:
> 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' }

syntax weirdness ...

> 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?

no, but you could try to add the parens there as well:
define_method(:"ferret_#{field}") do
...

Jens

-- 
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[EMAIL PROTECTED] | www.webit.de
 
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to