How can I do the dictionary?

S

Siratinee Sukachai

I am a newbie but I'm familial with C#.
I can't find any dictionary class in Ruby.
I need to do like Dictionary<key, List<string>>

Can I do that in Ruby? If yes, how?
Big thanks!
 
Z

Zhi-Qiang Lei

[Note: parts of this message were removed to make it a legal post.]

I think what you seek is Hash.


I am a newbie but I'm familial with C#.
I can't find any dictionary class in Ruby.
I need to do like Dictionary<key, List<string>>

Can I do that in Ruby? If yes, how?
Big thanks!


Best regards,
Zhi-Qiang Lei
(e-mail address removed)
 
7

7stud --

Siratinee Sukachai wrote in post #993714:
I am a newbie but I'm familial with C#.
I can't find any dictionary class in Ruby.
I need to do like Dictionary<key, List<string>>

Can I do that in Ruby? If yes, how?
Big thanks!

my_hash = {
'fruits' => ['apple', 'pear'],
'cars' => ['VW', 'BMW', 'Ford']
}

p my_hash['cars']

--output:--
["VW", "BMW", "Ford"]


my_hash['rocks'] = ['granite', 'quartzite']
p my_hash

--output:--
{"fruits"=>["apple", "pear"], "cars"=>["VW", "BMW", "Ford"],
"rocks"=>["granite", "quartzite"]}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,811
Messages
2,569,693
Members
45,477
Latest member
IsidroSeli

Latest Threads

Top