class Object

Public Instance Methods

acceptor(question) click to toggle source

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.

# File lib/autobot/utils.rb, line 24
def acceptor(question)
   print "#{question} [YyNn]"
   answer = $stdin.gets.downcase.strip

   answer == "y"
end
which(cmd) click to toggle source

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.

# 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