File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ line options parser code.
69
69
In addition to #cli, CLI.K provides the #ask method. This is a very simple
70
70
command line query method.
71
71
72
- ans = ask "Are you nice? [Y/N ]"
72
+ ans = ask "Are you nice? [Y/n ]"
73
73
74
74
Other Ruby libraries have their own take on the #ask method, and this very
75
75
simple 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
6
6
# via the console. A prompt will be sent to $stdout,
7
7
# if given, and the input taken from $stdin...
8
8
#
9
- # ask "Are you happy? [Yn]"
9
+ # ask "Are you happy? [Yn]", "Y"
10
10
#
11
11
# On the command line one would see...
12
12
#
@@ -19,11 +19,15 @@ module Kernel
19
19
# The ask method would return "Y".
20
20
#
21
21
# Returns [String]
22
- def ask ( prompt = nil )
22
+ def ask ( prompt = nil , default_answer = nil )
23
23
$stdout << "#{ prompt } "
24
24
$stdout. flush
25
- $stdin. gets . chomp!
25
+ ans = $stdin. gets . chomp!
26
+ if ans == ''
27
+ default_answer
28
+ else
29
+ ans
30
+ end
26
31
end
27
-
28
32
end
29
33
You can’t perform that action at this time.
0 commit comments