From: Robert Klemme Date: 2004-09-04T01:50:17+09:00 Subject: Re: define a class method "Benny" schrieb im Newsbeitrag news:2prk1uFo78jvU1@uni-berlin.de... > dear list, > > I know, I can use send( :define_method, "testmeth") to > define an object method (i.e. a singleton method of a class). > > but how can I define a "normal" method within the class (that is available > for the objects) > > I simply want to define method to which I pass the name and the code for a > new method to created with a certain class > > > any ideas? > > > regards benny >> class Foo;end => nil >> Foo.define_method( :bar ) { "bar" } NoMethodError: private method `define_method' called for Foo:Class from (irb):2 >> Foo.instance_eval { define_method( :bar ) { "bar" } } => # >> Foo.new.bar => "bar" >> Cheers robert