From: "Mauricio Fernández" Date: 2004-04-17T07:42:43+09:00 Subject: Re: Class instance method can't be defined in a module? On Sat, Apr 17, 2004 at 07:32:07AM +0900, John Platte wrote: > Trying to work some attr_accessor - style magic so I can refactor a > bunch of menial methods into a single declaration. Can't subclass, so > I'm trying to do it with a module. > > In the code below, I expect both of the "puts" lines to work on the > "abc" string, but I can't figure out what I'm missing. Can anyone > enlighten me here? batsman@tux-chan:/tmp$ cat fdgdf.rb module FooModule def delegate(*methods) methods.each do |method| define_method(method){|*a| @new_receiver.send(method, *a) } end end end class TryIt extend FooModule delegate :intern delegate :capitalize def initialize(obj) @new_receiver = obj end end t = TryIt.new("abc") puts t.intern puts t.capitalize batsman@tux-chan:/tmp$ ruby fdgdf.rb abc Abc -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com The documentation is in Japanese. Good luck. -- Rich $alz