File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ line options parser code.
6969In addition to #cli, CLI.K provides the #ask method. This is a very simple
7070command line query method.
7171
72- ans = ask "Are you nice? [Y/N ]"
72+ ans = ask "Are you nice? [Y/n ]"
7373
7474Other Ruby libraries have their own take on the #ask method, and this very
7575simple implementation can just as soon be overridden. No biggy. But it's nice
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ module Kernel
66 # via the console. A prompt will be sent to $stdout,
77 # if given, and the input taken from $stdin...
88 #
9- # ask "Are you happy? [Yn]"
9+ # ask "Are you happy? [Yn]" "Y"
1010 #
1111 # On the command line one would see...
1212 #
@@ -19,10 +19,15 @@ module Kernel
1919 # The ask method would return "Y".
2020 #
2121 # Returns [String]
22- def ask ( prompt = nil )
22+ def ask ( prompt = nil , default_answer = Y )
2323 $stdout << "#{ prompt } "
2424 $stdout. flush
25- $stdin. gets . chomp!
25+ ans = $stdin. gets . chomp!
26+ if ans == ''
27+ default_answer
28+ else
29+ ans
30+ end
2631 end
2732
2833end
You can’t perform that action at this time.
0 commit comments