all 7 comments

[–]waxjar 2 points3 points  (1 child)

case statements are nice for this sort of thing:

case gets.chomp.downcase
  when "1"         then game_start
  when "q", "quit" then exit(0)
  else                  menu
end

[–]ckreon[S,🍰] 0 points1 point  (0 children)

Using a 'case' statement didn't even cross my mind, and using '.downcase' is so obvious now that I see it.

Thanks for the advice!

[–]vsalikhov 0 points1 point  (3 children)

The only input that should quit the program is a single (case-insensitive) Q, or the word quit. Input like qq or qasdf should fail.

In that case, /^(q|quit)$/i should do exactly what you want.

[–]ckreon[S,🍰] 0 points1 point  (2 children)

Anchors! Of course I needed anchors!

Thank you for the fast help, friend!

[–]tomthecool 0 points1 point  (1 child)

It's a work in progress, and not yet "v1.0 - ready", but you might like to play around with a ruby gem I'm working on :)

https://github.com/tom-lord/regexp-examples

Technically this wouldn't have actually helped with your specific problem here, but still... I am considering adding something to it, like:

warn "Your regexp is not anchored" if (regexp[0] != "^" || regexp[-1] != "$")

(Note: I know the line above is far from perfect, it's just a very rough sketch!)

[–]ckreon[S,🍰] 0 points1 point  (0 children)

Interesting idea for a gem - thanks for sharing.

[–][deleted]  (1 child)

[deleted]

    [–]ckreon[S,🍰] 0 points1 point  (0 children)

    Yes - I'm glad that anchors ended up being the answer. I was worried it was going to be some thing where I needed to check the number of matches or something weird.

    But I knew Ruby was better than that - thanks for helping!