summaryrefslogtreecommitdiff
path: root/lib/highline/question_asker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/highline/question_asker.rb')
-rw-r--r--lib/highline/question_asker.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/highline/question_asker.rb b/lib/highline/question_asker.rb
index bb10c9e..06e6647 100644
--- a/lib/highline/question_asker.rb
+++ b/lib/highline/question_asker.rb
@@ -105,13 +105,11 @@ class HighLine
# with keys provided by the Hash on {Question#gather}
# @return [Hash]
def gather_hash
- answers = {}
-
- question.gather.keys.sort.each do |key|
+ sorted_keys = question.gather.keys.sort_by(&:to_s)
+ sorted_keys.each_with_object({}) do |key, answers|
@highline.key = key
answers[key] = ask_once
end
- answers
end
@@ -133,15 +131,18 @@ class HighLine
end
def answer_matches_regex(answer)
- (question.gather.is_a?(::String) && answer.to_s == question.gather) ||
- (question.gather.is_a?(Regexp) && answer.to_s =~ question.gather)
+ if question.gather.is_a?(::String) || question.gather.is_a?(Symbol)
+ answer.to_s == question.gather.to_s
+ else question.gather.is_a?(Regexp)
+ answer.to_s =~ question.gather
+ end
end
def gather_answers_based_on_type
case question.gather
when Integer
gather_integer
- when ::String, Regexp
+ when ::String, Symbol, Regexp
gather_regexp
when Hash
gather_hash