From: Daniel Schierbeck Date: 2005-10-27T03:27:06+09:00 Subject: Re: A comparison by example of keyword argument styles Eric Mahurin wrote: > --- Yukihiro Matsumoto wrote: > > >>Hi, >> >>In message "Re: A comparison by example of keyword argument >>styles" >> on Tue, 25 Oct 2005 00:15:35 +0900, Eric Mahurin >> writes: >> >>|> otherwise we >>|> must change the code as >>|> >>|> def foo(*args, **keys) >>|> bar(*args, **keys) >>|> end >>|> >>|> everywhere, to just do delegation. >>| >>|or rather: >>| >>|def foo(*args, **keys, &block) >>| bar(*args, **keys, &block) >>|end >>| >>|What's wrong with having to do that? >> >>It's longer than it is really needed. I want to delegate >>everything >>I've passed, that's all. I'd rather delegate blocks as well >>when I >>write bar(*args). >> >> matz. > > > Actually, I think the best way to do delegation would be to > have a #define_method that didn't change self. If you wanted > to delegate obj.bar to #foo (in the current class), it would be > nice to be able to do something like this: > > # Proc/Method arg instead of block will leave self alone > define_method(:foo,obj.method(:bar)) > > Right now (only in v1.9 - where a block can be a block > argument), you'd do it like this: > > define_method(:foo) { |*args,&block| > obj.bar(*args,&block) > } > > or: > > meth = obj.method(:bar) > define_method(:foo) { |*args,&block| > meth.call(*args,&block) > } > > > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > > Why not simply this: def foo(*args, &block) deletegate_to obj, :meth1, :meth2 # same as obj.meth1.meth2(*args, &block) end Cheers, Daniel