Class: Util
- Inherits:
-
Object
- Object
- Util
- Defined in:
- lib/util.rb
Class Method Summary collapse
-
.get_numeric_input(mssg) ⇒ Object
—————————————————————————————————— Retrieves numeric input only from the command line.
-
.is_number?(input) ⇒ Boolean
—————————————————————————————————— Checks if the input is a number.
Class Method Details
.get_numeric_input(mssg) ⇒ Object
Retrieves numeric input only from the command line
mssg: The message to display that requests the input
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/util.rb', line 17 def self.get_numeric_input mssg begin while true print mssg input = gets().chomp() if Util.is_number? input return input.to_i else puts "Input is not a number" end end rescue Exception => e puts e. end end |
.is_number?(input) ⇒ Boolean
Checks if the input is a number
input: The object that will be tested
8 9 10 |
# File 'lib/util.rb', line 8 def self.is_number? input true if Float input rescue false end |