From: nobuyoshi nakada Date: 2005-10-27T16:47:07+09:00 Subject: Re: A comparison by example of keyword argument styles Hi, At Thu, 27 Oct 2005 01:58:09 +0900, Eric Mahurin wrote in [ruby-talk:162763]: > > > That's the ticket. I thought &method would be the same as > > > &(method.to_proc) - they both convert a Method to a Proc. > > But > > > > Yes, they are equivalent. > > Sorry, I thought I tried this. I guess not. I falsely assumed > that define_method(:foo,&meth) and define_method(:foo,meth) did > the same thing (they do with Proc's). I guess not. I meant that &foo calls foo.to_proc internally. > Here is a full suite to show what happens with > procs/methods/blocks/to_proc/method(:call) and define_method: > > hello_world = "hello world!".method(:[]) > me = lambda { self } > > Test = Class.new { > define_method(:hi1,&hello_world) > define_method(:hi2,&(hello_world.to_proc)) > define_method(:hi3,hello_world) > define_method(:hi4,hello_world.to_proc) > define_method(:me0) { self } > define_method(:me1,&me) > define_method(:me2,&(me.to_proc)) > define_method(:me3,&(me.method(:call).to_proc)) It is same as: define_method(:me3) {me.call} Object#method encloses its context, including "self". -- Nobu Nakada