From: Matthew Smillie Date: 2006-08-10T07:22:40+09:00 Subject: Re: Newbie: Symbol as array index error On Aug 9, 2006, at 23:03, Joshua Muheim wrote: > Hi all > > I'm terrible sorry for this newbie question, but I really can't figure > it out. :O > > 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... 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.