# Newbie: Symbol as array index error

**URL:** <https://www.ruby-forum.com/t/newbie-symbol-as-array-index-error/64566>\
**Category:** Ruby\
**Created:** [August 10, 2006, 12:03am UTC](https://www.ruby-forum.com/t/newbie-symbol-as-array-index-error/64566 "2006-08-10T00:03:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 10, 2006, 12:03am UTC](https://www.ruby-forum.com/t/newbie-symbol-as-array-index-error/64566/1 "2006-08-10T00:03:29Z")

</div>

Hi all

I’m terrible sorry for this newbie question, but I really can’t figure  
it out. 😮

I want to create a method that accepts a hash of parameters:

def write\_email \*args  
‘’  
end

But when I call it…

\<%= write\_email :name =\> ‘info’, :domain =\> ‘atelier-schmuck.ch’,  
:subject =\> ‘www.atelier-schmuck.ch - Kontaktanfrage’, :body =\> ‘Hoi du!  
:-)’ %\>

I get this error:

Symbol as array index

Where’s the problem? Thanks for help…  
Joshua

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 10, 2006, 12:23am UTC](https://www.ruby-forum.com/t/newbie-symbol-as-array-index-error/64566/2 "2006-08-10T00:23:37Z")

</div>

On Aug 9, 2006, at 23:03, Joshua M. wrote:

> Where’s the problem? Thanks for help…

It’s the splat operator in the method definition, which tells Ruby  
that args is an array. You don’t need it, since the hash literal in  
the method call is a single hash, not a collection of separate  
arguments.

def test\_the\_first \*args  
puts args.class  
p args  
end

test\_the\_first :foo =\> :bar, :moose =\> :squirrel  
Array  
[{:foo=\>:bar, :moose=\>:squirrel}]

def test\_the\_second args  
puts args.class  
p args  
end

test\_the\_second :foo =\> :bar, :moose =\> :squirrel  
Hash  
{:foo=\>:bar, :moose=\>:squirrel}

Hope that helps.

matthew smillie.

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [August 10, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/newbie-symbol-as-array-index-error/64566/3 "2006-08-10T15:54:10Z")

</div>

Thanks a lot, I got it now. 🙂
