From: "mame (Yusuke Endoh)" Date: 2012-05-23T00:23:12+09:00 Subject: [ruby-core:45185] [ruby-trunk - Bug #6476][Rejected] Proc unrolls an array even without splat Issue #6476 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected Hello, prijutme4ty (Ilya Vorontsov) wrote: > pr_def(*[1,2,3]) # => [1] + [2,3] It should be: "1 + [2, 3]" > Is it right behaviour or such unsplatting is a bug? It is the spec. A method and lambda use a strict rule for arguments, but a proc uses a flexible one: it does not distinguish multiple arguments from one array argument. def foo yield 1, 2 end def bar yield [1, 2] end f = proc {|x, y| p x + y } foo(&f) #=> 3 foo(&f) #=> 3 f.call(1, 2) #=> 3 f.call([1, 2]) #=> 3 -- Yusuke Endoh ---------------------------------------- Bug #6476: Proc unrolls an array even without splat https://bugs.ruby-lang.org/issues/6476#change-26765 Author: prijutme4ty (Ilya Vorontsov) Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: 1.9.3p194 Normal behaviour: def pr_def(recv,*args) puts "#{recv.inspect} + #{args.inspect}" end pr_def(*[1,2,3]) # => [1] + [2,3] pr_def([1,2,3]) # => [1,2,3] + [] pr_def([[1,2,3]]) # => [[1,2,3]] + [] pr_lambda = lambda{|recv,*args| puts "#{recv.inspect} + #{args.inspect}"} pr_lambda.call(*[1,2,3]) # => [1] + [2,3] pr_lambda.call([1,2,3]) # => [1,2,3] + [] pr_lambda.call([[1,2,3]]) # => [[1,2,3]] + [] But Proc acts in a different way. pr_proc = Proc.new{|recv,*args| puts "#{recv.inspect} + #{args.inspect}"} pr_proc.call(*[1,2,3]) # => 1 + [2,3] pr_proc.call([1,2,3]) # => 1 + [2,3] pr_proc.call([[1,2,3]]) # => [1,2,3] + [] Is it right behaviour or such unsplatting is a bug? -- http://bugs.ruby-lang.org/