behavior of proc { || } on 1.9

P

Paul Brannan

Is this expected behavior?

cout@bean:~$ ruby -v -e 'proc { || }.call 42'
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
-e:1: wrong number of arguments (1 for 0) (ArgumentError)
from -e:1:in `call'
from -e:1
cout@bean:~$ ruby1.9 -v -e 'proc { || }.call 42'
ruby 1.9.0 (2007-05-26 patchlevel 0) [i686-linux]
 
S

Skye Shaw!@#$

Is this expected behavior?

cout@bean:~$ ruby -v -e 'proc { || }.call 42'
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
-e:1: wrong number of arguments (1 for 0) (ArgumentError)
from -e:1:in `call'
from -e:1
cout@bean:~$ ruby1.9 -v -e 'proc { || }.call 42'
ruby 1.9.0 (2007-05-26 patchlevel 0) [i686-linux]

1.9 gives no such error?
Seems as 1.8.6 is right on, yet on my system, under 1.8.5 (patchlevel
35):

irb(main):001:0> Proc.new{|a| p a}.call 69,70
(irb):9: warning: multiple values for a block parameter (2 for 1)
from (irb):9
[69, 70]
=> nil
irb(main):002:0> Proc.new{|a,b| p a}.call 69,70,71
69
=> nil

Considering b isnt optional, i.e. specified as "*b" (where b[1] ==
71)
Shouldn't this raise a 3 for 2 warning?

irb(main):003:0> def what(a,b)
irb(main):004:1> p a
irb(main):005:1> p b
irb(main):006:1> end
=> nil
irb(main):007:0> what(1,2,3)
ArgumentError: wrong number of arguments (3 for 2)
from (irb):5:in `what'
from (irb):5
from :0



I understand that there are differences between a function definition
and a Proc object, but why are there differences in the way they treat
their arguments?
 
B

Brian Mitchell

Is this expected behavior?

cout@bean:~$ ruby -v -e 'proc { || }.call 42'
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
-e:1: wrong number of arguments (1 for 0) (ArgumentError)
from -e:1:in `call'
from -e:1
cout@bean:~$ ruby1.9 -v -e 'proc { || }.call 42'
ruby 1.9.0 (2007-05-26 patchlevel 0) [i686-linux]

In 1.9 proc behaves more like Proc.new IIRC.

Brian.
 

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,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top