From: alxtskrnk@... Date: 2015-02-10T16:23:51+00:00 Subject: [ruby-core:68082] [Ruby trunk - Bug #10837] spatting a single element array produces an array instead of a single value for return and next Issue #10837 has been updated by bug hit. Marc-Andre Lafortune wrote: > bug hit wrote: > > `b = *[a]` is `b = [a]` why? > > `(next|return) *[a]` is `(next|return) [a]` why? > > I agree, this can be surprising. > > The reason for the behavior is that `return 1, 2`, strictly speaking, shouldn't be valid Ruby as you can only return one value. Instead of forbidding it, `return 1, 2` is automatically converted to `return [1, 2]`. They are equivalent. So `return *array` is converted to `return [*array]`, and that holds even in the cases where `array` contains one or no element (or isn't an array). > > The same can be said for `next` and `=`. > > HTH So it seems it's an implementation artifact. Would it not be better if semantics of splatting were consistent, i.e. rvalue splat would always destructure the array? ---------------------------------------- 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-51465 * 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/