Project

General

Profile

Actions

Bug #7621

closed

ブロック引数にデフォルト値を指定したときに配列を渡した際の挙動が1.9.3と変わっている

Added by takkanm (三村 益隆) almost 12 years ago. Updated almost 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.0.0dev
Backport:
[ruby-dev:46801]

Description

=begin
ブロックをとるメソッドや Proc.new で、ブロック引数にデフォルト値を指定したときに配列を渡した際の
挙動が 1.9.3 と変わっています。

proc のとき

$ ruby -v -e 'proc {|ary = []| p ary }.([1, 2, 3])'
ruby 2.0.0dev (2012-12-25) [x86_64-darwin12.2.1]
1

$ ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
[1, 2, 3]

block のとき

$cat yield_ary.rb
def yield_ary
yield([1, 2, 3])
end

yield_ary {|ary = []| p ary }

$ ruby -v yield_ary.rb
ruby 2.0.0dev (2012-12-25) [x86_64-darwin12.2.1]
1

$ ruby -v yield_ary.rb
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
[1, 2, 3]

lambda のときの挙動は 1.9.3 と同じようです。

$ ruby -v -e 'lambda {|ary = []| p ary }.([1, 2, 3])'
ruby 2.0.0dev (2012-12-25) [x86_64-darwin12.2.1]
[1, 2, 3]

$ ruby -v -e 'lambda {|ary = []| p ary }.([1, 2, 3])'
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
[1, 2, 3]
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #5730: Optinal block parameters assigns wrongClosed12/09/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0