Accessing hash values

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"]

Thanks.

···

--
Posted via http://www.ruby-forum.com/.

Sean Stephenson wrote:

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")

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

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.

···

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"]

--
Iñaki Baz Castillo <ibc@aliax.net>

Joel VanderWerf wrote:

Sean Stephenson wrote:

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")

AWESOME! Thanks for the quick reply Joel.

···

--
Posted via http://www.ruby-forum.com/\.

Iñaki Baz Castillo wrote:

···

El Miércoles, 2 de Septiembre de 2009, Sean Stephenson escribió:

    "computer-03"=>"bob"
'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.

And thanks to you as well Iñaki.
--
Posted via http://www.ruby-forum.com/\.