Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ line options parser code.
In addition to #cli, CLI.K provides the #ask method. This is a very simple
command line query method.

ans = ask "Are you nice? [Y/N]"
ans = ask "Are you nice? [Y/n]"

Other Ruby libraries have their own take on the #ask method, and this very
simple implementation can just as soon be overridden. No biggy. But it's nice
Expand Down
12 changes: 8 additions & 4 deletions lib/clik/ask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Kernel
# via the console. A prompt will be sent to $stdout,
# if given, and the input taken from $stdin...
#
# ask "Are you happy? [Yn]"
# ask "Are you happy? [Yn]", "Y"
#
# On the command line one would see...
#
Expand All @@ -19,11 +19,15 @@ module Kernel
# The ask method would return "Y".
#
# Returns [String]
def ask(prompt=nil)
def ask(prompt=nil, default_answer=nil)
$stdout << "#{prompt}"
$stdout.flush
$stdin.gets.chomp!
ans = $stdin.gets.chomp!
if ans == ''
default_answer
else
ans
end
end

end