module Executable::Utils
Some handy-dandy CLI utility methods.
Constants
- BOOLEAN_MAP
Strings to interprest as boolean values.
Public Instance Methods
ask(question, options={})
click to toggle source
Query the user for an answer.
# File lib/executable/utils.rb, line 29 def ask(question, options={}) print "#{question} [default: #{options[:default]}] " reply = STDIN.readline.chomp if reply.empty? options[:default] else reply end end
no?(question, options={})
click to toggle source
Query the user for a yes/no answer, defaulting to no.
# File lib/executable/utils.rb, line 22 def no?(question, options={}) print "#{question} [y/N] " input = STDIN.readline.chomp.downcase BOOLEAN_MAP[input] || false end
yes?(question, options={})
click to toggle source
Query the user for a yes/no answer, defaulting to yes.
# File lib/executable/utils.rb, line 15 def yes?(question, options={}) print "#{question} [Y/n] " input = STDIN.readline.chomp.downcase BOOLEAN_MAP[input] || true end