# Syntax error with array interpolation

**URL:** <https://www.ruby-forum.com/t/syntax-error-with-array-interpolation/107709>\
**Category:** Ruby\
**Created:** [June 25, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/syntax-error-with-array-interpolation/107709 "2007-06-25T16:43:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [June 25, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/syntax-error-with-array-interpolation/107709/1 "2007-06-25T16:43:05Z")

</div>

Below is a code snippet which gives me some headache:

def headache  
yield(\*(foo(1)),“bar”)  
end

def foo(n)  
[n,n+2,n+5]  
end

headache { |a,b,c,d| puts a.to\_s; puts b.to\_s; puts c.to\_s; puts d }

I had expected that this would print

1  
3  
6  
bar

But Ruby 1.8.5 complains:

./headache.rb: line 1: def: command not found  
./headache.rb: line 2: syntax error near unexpected token `*' '/headache.rb: line 2:` yield(\*(foo(1)),“bar”)

and Ruby 1.8.6 complains:

H:/tmp/headache.rb:2: syntax error, unexpected tSTRING\_BEG, expecting  
tAMPER  
yield(\*(foo(1)),“bar”) ^  
H:/tmp/headache.rb:2: syntax error, unexpected ‘)’, expecting kEND  
H:/tmp/headache.rb:10: syntax error, unexpected $end, expecting kEND

There must something be wrong with the way I’m doing array  
interpolation,  
but I can’t spot the error…

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [June 25, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/syntax-error-with-array-interpolation/107709/2 "2007-06-25T17:02:39Z")

</div>

Ronald F. wrote:

> Below is a code snippet which gives me some headache:
> 
> def headache  
> yield(\*(foo(1)),“bar”)  
> end

You can’t use a ‘splatted’ array anywhere in a method call except at the  
end:

def foo(a, b, c)  
p [a, b, c]  
end

foo(1, 2, \*[3]) #=\> works  
foo(1, \*[3], “asdf”) #=\> doesn’t work

I’m not quite sure why this should be, since it has an unambiguous  
meaning, unlike defining a method with a splat in the middle of the  
arguments:

def bar(a, \*b, c=0)  
…  
end

The splat operator is a bit mysterious to me in this regard…

best,  
Dan

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [June 25, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/syntax-error-with-array-interpolation/107709/3 "2007-06-25T17:04:05Z")

</div>

Daniel L. wrote:

> You can’t use a ‘splatted’ array anywhere in a method call except at the  
> end:

Pardon me: and before a block argument:  
foo(1, 2, \*[3], &block)

Dan
