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

T

Thomas Hafner

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
 
P

Phlip

Thomas said:
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...
 
R

Ryan Davis

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:
#<Class:0x428ec>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top