Issue #10837 has been updated by bug hit.


Naja Melan wrote:
> @bug hit
> 
> My apologies, it seems I'm mistaken. The splat operator does not just seem to coerce into array for all types:
> 
> ~~~ ruby
> a = { a: 1 }
> 
> p [a]   # [{:a=>1}]
> p *a    # [:a, 1]
> p [*a]  # [[:a, 1]]
> ~~~
> 
> It seems it calls `#to_a` on classes that implement this. I'm sorry if I create confusion in the ongoing discussion.

Also when it's already an array (a = *array), what you are asking ruby to do is first destructure the array, then coalesce it back into an array, essentially making a shallow copy, whereas what you actually want is to leave it alone.  Array.wrap leaves it alone. 



----------------------------------------
Bug #10837: spatting a single element array produces an array instead of a single value for return and next
https://bugs.ruby-lang.org/issues/10837#change-59644

* Author: bug hit
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
irb(main):013:0> ->{return *[1]}.()
=> [1]
irb(main):014:0> ->{next *[1]}.()
=> [1]
______________

*[x] should mean x as it already does for arguments 



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>