From: Eric Mahurin Date: 2005-10-27T01:07:49+09:00 Subject: Re: A comparison by example of keyword argument styles --- Trans wrote: > > Eric Mahurin wrote: > > The "method" above is not meant to mean whatever method you > > feel like. I'm talking about Object#method that returns a > > Method object for the method name/symbol given as an > argument. > > Ah, I see. I misinterpreted what you were asking for. Then > try: > > define_method(:foo,&obj.method(:bar).to_proc) > > T. That's the ticket. I thought &method would be the same as &(method.to_proc) - they both convert a Method to a Proc. But I guess Method#to_proc does some isolation so that define_method doesn't change self. We can also use this same technique to give define_method a Proc where we want to leave self alone: me = lambda { self } me.call # => main C = Class.new{ # Proc#method(:call) is effectively Proc#to_method define_method(:foo,me.method(:call).to_proc) define_method(:bar,me) } C.new.foo # => main C.new.bar # => # Now if 1.8 just had Proc's that could take blocks, I'd be able to get rid of some of my eval("def ...") statements and replace them with define_method. In 1.9, I think the above define_method/#to_proc way is the best way to do simple delegation. __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com