From: hipster Date: 2001-07-06T16:22:29+09:00 Subject: [ruby-talk:17394] Re: Adding a method to a class at the top-level On Fri, 06 Jul 2001 06:24:15 +0900, Guillaume Cottenceau wrote: > Comrades, > > > I'm looking for the "fastest" way to add a method to an existing class, in > a Ruby program. > > At first I thought there would be an elegant one-liner to do that, but > unfortunately, the following adds a Class method, not an Instance method: > > def Demo.aClassMethod; end > > > So the best way so far is: > > class Demo; def aclassMethod; end; end how about: class Aap end a = Aap.new Aap.class_eval("def noot; puts 'mies'; end") Aap.class_eval { def wim; puts 'zus'; end } a.noot #=> mies a.wim #=> zus Michel