# Ruby 1.9 splat in return statement, bug or feature?

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880>\
**Category:** Ruby\
**Created:** [February 17, 2007, 4:37am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880 "2007-02-17T04:37:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfharlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@pfharlock](https://www.ruby-forum.com/u/pfharlock)\
**Post date:** [February 17, 2007, 4:37am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880/1 "2007-02-17T04:37:42Z")

</div>

What’s going on with splat in 1.9?

$ ruby -e ‘def foo; return \*[1]; end; p foo’  
1

$ ruby-1.9 -e ‘def foo; return \*[1]; end; p foo’  
[1]

Gary W.

---

<div class="post-metadata">

**Author:** ![pfharlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@pfharlock](https://www.ruby-forum.com/u/pfharlock)\
**Post date:** [February 17, 2007, 5:03am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880/2 "2007-02-17T05:03:43Z")

</div>

From: Gary W. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# What’s going on with splat in 1.9?

# $ ruby -e ‘def foo; return \*[1]; end; p foo’

# 1

# $ ruby-1.9 -e ‘def foo; return \*[1]; end; p foo’

# [1]

consistency perhaps?

r@pc4all:~# ruby -e ‘def foo; return \*[1]; end; p foo’  
1  
r@pc4all:~# ruby -e ‘def foo; return \*[1,2]; end; p foo’  
[1, 2]

kind regards -botp

---

<div class="post-metadata">

**Author:** ![pfharlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@pfharlock](https://www.ruby-forum.com/u/pfharlock)\
**Post date:** [February 17, 2007, 5:58am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880/3 "2007-02-17T05:58:54Z")

</div>

PeÃ±a, Botp wrote:

> …
> 
> consistency perhaps?
> 
> r@pc4all:~# ruby -e ‘def foo; return \*[1]; end; p foo’  
> 1  
> r@pc4all:~# ruby -e ‘def foo; return \*[1,2]; end; p foo’  
> [1, 2]
> 
> kind regards -botp

It seems somehow less consistent when viewed another way though. I think  
splatting a literal array should be equivalent to having written a plain  
comma-delimited list:

def bar(\*args); end

bar 1  
bar(_[1])  
bar 1, 2  
bar(_[1, 2])

In which case, for return:

return \*[1] =\> return 1 =\> 1  
return \*[1, 2] =\> return 1, 2 =\> [1, 2]

Its not going to really bother me at any rate though.

---

<div class="post-metadata">

**Author:** ![pfharlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@pfharlock](https://www.ruby-forum.com/u/pfharlock)\
**Post date:** [February 17, 2007, 11:17am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880/4 "2007-02-17T11:17:04Z")

</div>

Hi,

In message “Re: ruby 1.9 splat in return statement, bug or feature?”  
on Sat, 17 Feb 2007 12:36:20 +0900, Gary W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|What’s going on with splat in 1.9?  
|  
|$ ruby -e ‘def foo; return \*[1]; end; p foo’  
|1  
|  
|$ ruby-1.9 -e ‘def foo; return \*[1]; end; p foo’  
|[1]

In 1.9, values (i.e. result of splat) are always represented by array,  
so that we won’t confuse array as an value with array as values  
representation.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![pfharlock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@pfharlock](https://www.ruby-forum.com/u/pfharlock)\
**Post date:** [June 3, 2009, 8:30am UTC](https://www.ruby-forum.com/t/ruby-1-9-splat-in-return-statement-bug-or-feature/85880/5 "2009-06-03T08:30:27Z")

</div>

Men thats a real bummer, i love “peeling” arrays like this:

a = \*[1] #=\> 1  
a = \*[1,2] # =\> [1,2]

Some of my code is gonna break.

Yukihiro M. wrote:

> Hi,
> 
> In message “Re: ruby 1.9 splat in return statement, bug or feature?”  
> on Sat, 17 Feb 2007 12:36:20 +0900, Gary W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> writes:
> 
> |What’s going on with splat in 1.9?  
> |  
> |$ ruby -e ‘def foo; return \*[1]; end; p foo’  
> |1  
> |  
> |$ ruby-1.9 -e ‘def foo; return \*[1]; end; p foo’  
> |[1]
> 
> In 1.9, values (i.e. result of splat) are always represented by array,  
> so that we won’t confuse array as an value with array as values  
> representation.
> 
> ```
> matz.
> 
> ```
