how to make "quit" at the end of "menu"

G

Gpy Good

I create a ruby program that need a menu from database:
menu={
"open file"=>"file.html",
"save file"=>"save_file.html",
"quit"=>"quit.rb"
}

puts menu.inspect

=>
{"open file"=>"file.html", "quit"=>"quit.rb", "save
file"=>"save_file.html"}

BUT,i hope that as I create menu's ordered
=>
{"open file"=>"file.html", "save
file"=>"save_file.html","quit"=>"quit.rb"}
 
G

Gpy Good

or,Is there have a hash method like to_map ?

puts menu.to_map.inspect
=>
{"open file"=>"file.html", "save
file"=>"save_file.html","quit"=>"quit.rb"}
 
B

Brian Candler

I create a ruby program that need a menu from database:
menu={
"open file"=>"file.html",
"save file"=>"save_file.html",
"quit"=>"quit.rb"
}

puts menu.inspect

=>
{"open file"=>"file.html", "quit"=>"quit.rb", "save
file"=>"save_file.html"}

BUT,i hope that as I create menu's ordered
=>
{"open file"=>"file.html", "save
file"=>"save_file.html","quit"=>"quit.rb"}

If ordering is important, don't use a hash.

menu = [
['open file','file.html'],
['save file','save_file.html'],
['quit','quit.rb'],
]
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top