--- nobu.nokada / softhome.net wrote:

> Hi,
> 
> At Thu, 27 Oct 2005 01:07:49 +0900,
> Eric Mahurin wrote in [ruby-talk:162757]:
> > 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.

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))
 define_method(:me4,me)
 define_method(:me5,me.to_proc)
 define_method(:me6,me.method(:call).to_proc)
}

t = Test.new
t.hi1(0,5) # => "hello"
t.hi2(0,5) # => "hello"
t.hi3(0,5) # TypeError: bind argument ...
t.hi4(0,5) # => "hello"
t.me0 # => #<Test:0x402e7edc> # self changed
t.me1 # => #<Test:0x402e7edc> # self changed
t.me2 # => #<Test:0x402e7edc> # self changed
t.me3 # => main
t.me4 # => #<Test:0x402e7edc> # self changed
t.me5 # => #<Test:0x402e7edc> # self changed
t.me6 # => main

define_method probably needs some documentation update to
describe this a little better.



		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com