From: Brian Candler Date: 2003-03-15T18:57:31+09:00 Subject: Re: dynamically create a method On Sat, Mar 15, 2003 at 05:35:09AM +0900, Joel VanderWerf wrote: > 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} > # > irb(main):004:0> 3.power 2 > 9 The following doesn't work with 1.6.8, has it been fixed in 1.8? class Foo < String; end Foo.instance_eval { define_method(:gsub,*a) { puts "hello"; super } } Foo.new("test").gsub(/t/,'z') >> x.rb:2: super called outside of method Regards, Brian.