From: dblack@... Date: 2003-04-27T08:25:20+09:00 Subject: Re: block.call vs. yield Hi -- On Sun, 27 Apr 2003, Hal E. Fulton wrote: > ----- Original Message ----- > From: > To: "ruby-talk ML" > Sent: Saturday, April 26, 2003 10:13 AM > Subject: Re: block.call vs. yield > > > > Maybe something like call_with_... or call_as... ? (Not sure what the > > ... would be.) > > call_as_block perhaps?? or just call_block ? Another thought: If Proc#call has method-like semantics, perhaps what's needed is a method with block-like semantics -- namely, Block#call. That, of course, would also mean "Block" would be needed :-) But in fact, there is a certain logic to this, I think: pr = Proc.new {|x,y| puts x,y} pr.call(1,2) # => 1\n2\n pr.call(1) # => error but then: pr.to_block.call(1) # => 1\nnil\n Also, of course: b = Block.new {|x,y| puts x,y} b.call(1,2,3,4,5) # => 1\n2\n Quick and probably badly designed implementation: class Block < Proc private; def callback(*args); yield(args); end public; def call(*args); callback(*args,&self); end end class Proc def to_block Block.new &self end end David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav