Scripsit ille ?Rudolf Polzer? <abuse / durchnull.de>: > Scripsit ille ?Joel VanderWerf? <vjoel / PATH.Berkeley.EDU>: > > Rudolf Polzer wrote: > > > But I'd still like to know how to dynamically create a method with a > > > dynamically given name. If possible, without such a hackery. > > > > irb(main):003:0> Fixnum.instance_eval {define_method(:power) do |a| self > > ** a end} > > #<Proc:0x40210220@(irb):3> > > irb(main):004:0> 3.power 2 > > 9 > > > > The instance_eval is because it's a private method. > > Thanks... but where is it documented? I know rb_define_method (so I > should have just tried without the rb_)... And... it doesn't work here because "self" refers to the class Fixnum, not to the Fixnum object: rpolzer@katsuragi rpolzer $ irb irb(main):001:0> Fixnum.instance_eval {define_method(:power) do |a| self ** a end} => #<Proc:0x4006bf00> irb(main):002:0> 3.power 2 NameError: undefined method `**' for Fixnum:Class from (irb):1 from (irb):1:in `power' from (irb):2 I have Ruby 1.6.8. Do I need another way to access the "self"? -- [mpg123d] Just playing: .../MP3/ayumi hamasaki/a best/07 trauma.mp3 *PLONCK* [Pitt Marin in de.comm.technik.dsl]