Class: Shell::Input

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

Class Method Summary collapse

Class Method Details

.textObject



20
21
22
23
24
25
26
# File 'lib/shell/shell.rb', line 20

def self.text
  begin
    STDOUT.flush
    STDIN.gets.strip
  rescue
  end
end

.yesno(message) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/shell/shell.rb', line 28

def self.yesno message
  STDOUT.flush
  has_result = false
  while has_result == false
    print message.strip + " "
    input = STDIN.gets.strip
    
    if input == "yes" or input == "y" then
      final_input = "yes"
    elsif input == "no" or input == "n" then
      final_input = "no"
    end
    
    if ( final_input == "yes" or final_input == "no" )
      has_result = true
    end
  end
  
  if final_input == "yes"
    result = true
  else
    result = false
  end
  result
end