[#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:42278] Re: メニューのループについて

From: "Yasushi Ando" <andyjpn@...>
Date: 2006-05-27 15:26:49 UTC
List: ruby-list #42278
安藤と申します。

>  if /^q(u(i(t)?)?)?$/ =~ line

if 'quit' =~ /^#{line}.*/i
こうするのはどうでしょう?

On 27/05/06, Hiroshi Yuki <hyuki@hyuki.com> wrote:
> 結城です。
>
> > やりたいことは、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)
>
>
>
>


-- 
// ANDO Yasushi
// andyjpn@gmail.com
// http://techno.hippy.jp/rorwiki

In This Thread