[#42243] コミュニティと宗教の分離について — Beyond <beyond@...>

14 messages 2006/05/21

[#42267] メニューのループについて — リックス <rubyer4649@...>

りっくすです

21 messages 2006/05/27

[#42301] Re: メニューのループについて — "conundrum /" <conundrum@...>

conundrumです。

11 messages 2006/05/28

[ruby-list:42276] Re: メニューのループについて

From: Hiroshi Yuki <hyuki@...>
Date: 2006-05-27 14:49:42 UTC
List: ruby-list #42276
結城です。

> やりたいことは、1ー3を押してるときは何回もメニューが表
> 示されqを押したときはすぐに終了させたい

menu = {
  '1' => 'Test one.',
  '2' => 'Test two.',
  '3' => 'Test three.',
}

def menu.display
  keys.sort.each {|key|
    puts "#{key} : #{self[key]}"
  }
  puts "Choose #{keys.sort.join(', ')} or quit."
end

menu.display
while line = gets.chomp
  if /^q(u(i(t)?)?)?$/ =~ line
    break
  elsif menu[line]
    puts menu[line]
  else
    menu.display
  end
end
puts "Quit."

# 元の質問の主旨からだいぶ外れていてすみません。

----
結城浩 http://www.hyuki.com/
http://www.textfile.org/
In the beginning God created the heaven and the earth. (Genesis 1:1)



In This Thread