From: "Iñaki Baz Castillo" Date: 2009-09-02T07:49:53+09:00 Subject: Re: accessing hash values El Miércoles, 2 de Septiembre de 2009, Sean Stephenson escribió: > Hi all, this is my first post to the Ruby Forum. Cheers. And thanks for > helping out a newb. > > Quesiton: How do you access multiple values from a hash? > > For Example, I have a hash of computer names, and their associated user. > > the_system = { > "computer-01"=>"jill", > "computer-02"=>"jack", > "computer-03"=>"bob" > } > > > If I want to access the user of one machine, this works great: > > puts the_system["computer-01"] > =>jill > > > But how do I return multiple user names? (The below throws an error: > 'wrong number of arguments'.) > > puts the_system["computer-01", "computer-02"] the_system.values_at("computer-01","computer-02") => ["jill", "jack"] Note that it returns an Array. Note: Tested in Ruby1.9 but not in 1.8. -- Iñaki Baz Castillo