How to fix this bug? (Ruby Hard Way book)

Hi all,

I am working through Learn Ruby the Hard way and am a bit unsure as to
how to tackle the following bug. A asked an experienced friend for help
and he suggested using regular expressions. Is there a simpler way to
approach this?

The problem is here:

http://ruby.learncodethehardway.org/book/ex35.html

On line 7/8 the author states there is a bug. I presume the bug is that
it doesn’t capture all types of integer…But without a way to confirm
whether the input is an integer, how can I fix this?

If someone could point me in the right direction I’d really appreciate
it!

Thanks :slight_smile:

Luke Bennellick wrote in post #1154243:

Hi all,

Learn Ruby the Hard Way

On line 7/8 the author states there is a bug.
========================================
print "> "
choice = $stdin.gets.chomp

this line has a bug, so fix it

if choice.include? “0” or choice.include? “1”
how_much = choice.to_i
else
dead(“Man, learn to type a number.”)
end

if user type a mix of number and letter, there are no detection.

the test should be : choice=~/^\d+$/ ?..