[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

anonymous class, body defined by Proc.new vs. lambda

Thomas Hafner

4/25/2009 9:14:00 PM

Hello,

this is OK for both, Ruby 1.8 and 1.9:
f = Proc.new{}; Class.new(&f)

But why is that valid for Ruby 1.8 only?
f = lambda{}; Class.new(&f)

Ruby 1.9 complains
`initialize': wrong number of arguments (1 for 0) (ArgumentError)
from ./now.rb:21:in `new'
from ./now.rb:21:in `<main>'

Regards
Thomas
2 Answers

Phlip

4/25/2009 9:31:00 PM

0

Thomas Hafner wrote:

> Ruby 1.9 complains
> `initialize': wrong number of arguments (1 for 0) (ArgumentError)
> from ./now.rb:21:in `new'
> from ./now.rb:21:in `<main>'

Just a guess does this fix it?

f = lambda{|o| }; Class.new(&f)

Something to do with lambdas defend their arity...

Ryan Davis

4/25/2009 9:43:00 PM

0


On Apr 25, 2009, at 14:20 , Thomas Hafner wrote:

> this is OK for both, Ruby 1.8 and 1.9:
> f = Proc.new{}; Class.new(&f)
>
> But why is that valid for Ruby 1.8 only?
> f = lambda{}; Class.new(&f)
>
> Ruby 1.9 complains
> `initialize': wrong number of arguments (1 for 0) (ArgumentError)
> from ./now.rb:21:in `new'
> from ./now.rb:21:in `<main>'

the error message tells you why. it isn't hard to figure out what the
arg is either:

>> f = lambda{|x| p x }; Class.new(&f)
#<Class:0x428ec>