Top Level Namespace

Defined Under Namespace

Modules: Autobot

Instance Method Summary collapse

Instance Method Details

#acceptor(question) ⇒ Object

Public: Prints a question and waits for a yes-no answer.

question - An arbitrary string of your choise.

Returns true if the user answered yes, false otherwise.



24
25
26
27
28
29
# File 'lib/autobot/utils.rb', line 24

def acceptor(question)
   print "#{question} [YyNn]"
   answer = $stdin.gets.downcase.strip

   answer == "y"
end

#which(cmd) ⇒ Object

Public: Retrieve the location of an executable (mimics ‘which` behaviour) Ref.: stackoverflow.com/a/5471032

cmd - The command name to check

Returns the path of an executable if it is found, nil otherwise.



7
8
9
10
11
12
13
14
15
16
# File 'lib/autobot/utils.rb', line 7

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    }
  end
  return nil
end