Project

General

Profile

Actions

Bug #1372

closed

Kernel.catch not accepting &block

Added by sunaku (Suraj Kurapati) over 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
Backport:
[ruby-core:23175]

Description

=begin
Please observe:

$ cat catch.rb
b = lambda { throw :foo }
catch :foo, &b

$ multiruby catch.rb

VERSION = 1.8.7-p72
CMD = ~/.multiruby/install/1.8.7-p72/bin/ruby catch.rb

RESULT = 0

VERSION = 1.8.6-p368
CMD = ~/.multiruby/install/1.8.6-p368/bin/ruby catch.rb

RESULT = 0

VERSION = 1.9.1-p0
CMD = ~/.multiruby/install/1.9.1-p0/bin/ruby catch.rb

catch.rb:2:in catch': wrong number of arguments (1 for 0) (ArgumentError) from catch.rb:2:in '

RESULT = 256

TOTAL RESULT = 1 failures out of 3

Passed: 1.8.6-p368, 1.8.7-p72
Failed: 1.9.1-p0
=end

Actions #1

Updated by ko1 (Koichi Sasada) over 15 years ago

=begin
Suraj Kurapati wrote::

$ cat catch.rb
b = lambda { throw :foo }
catch :foo, &b
...
catch.rb:2:in catch': wrong number of arguments (1 for 0) (ArgumentError) from catch.rb:2:in '

Proc object generated by lambda method is checked argument number
strictly. The block which passed to catch method is called with one
argument (tag). Therefore an error is occuered at Proc#call in your
script (Proc#call is called with one argument, but lambda block can't
accept any argument).

Following script are accepted.

b = lambda {|tag| p tag; throw :foo }
catch :foo, &b # accepted

b = proc {throw :foo }
catch :foo, &b # accepted

--
// SASADA Koichi at atdot dot net

=end

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 15 years ago

  • Status changed from Open to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0