Benny
(Benny)
1
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
Robert
(Robert)
2
"Benny" <linux@marcrenearns.de> 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" } }
=> #<Proc:0x10180da0@(irb):3>
Foo.new.bar
=> "bar"
Cheers
robert