Class: Util

Inherits:
Object
  • Object
show all
Defined in:
lib/util.rb

Class Method Summary collapse

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.message
  end
end

.is_number?(input) ⇒ Boolean


Checks if the input is a number

input: The object that will be tested


Returns:

  • (Boolean)


8
9
10
# File 'lib/util.rb', line 8

def self.is_number? input
  true if Float input rescue false
end