From: Daniel Berger Date: 2005-05-17T20:36:39+09:00 Subject: Re: Forwardable, reworked --- Robert McGovern wrote: > > Nice work! I wonder if you could also add a nicer > interface while you > > are here enhancing things. I'd like to do this: > > > > class Foo > > extend Forwardable > > > > delegate :to_i => :@number > > delegate [:to_s, :reverse] => :@string > > > > def initialize > > @number = 5 > > @string = "foobar" > > end > > end > > That is very sweet, if possible I'd like to see that > style added. > > Rob This should do the trick: def delegate(hash) hash.each{ |methods, accessor| methods = methods.to_s if methods.kind_of?(Symbol) methods.each{ |method| def_instance_delegator(accessor, method) } } end If anyone has a better approach please let me know. Otherwise, I'll add some tests for this, then submit the whole thing as a patch. Regards, Dan Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html