lib/mixins/askable.rb in auser-poolparty-1.3.4 vs lib/mixins/askable.rb in auser-poolparty-1.3.5
- old
+ new
@@ -13,10 +13,11 @@
end
rescue Exception => e
colored_say e.inspect
exit 0
end
+ answer
end
def ask_with_help(opts={}, &block)
help_str = opts[:help]
message = opts[:message]
@@ -54,17 +55,13 @@
print substitute_color_tags(str)
end
def choose(str, choices={}, opts={}, &block)
colored_say(str)
- choices.each do |k,v|
- colored_say("#{k}) #{v}")
- end
- colored_print((opts[:prompt] || "> "))
- pick = gets.chomp.to_i
- yield choices[pick] if block
- choices[pick]
+ answer = ask(choices)
+ yield answer if block
+ answer
end
def wait
begin
STDIN.readline unless auto_install # -y passed
@@ -128,10 +125,12 @@
# get the answer, chomp it, etc.
def ask
case @question
when String
ask_string
+ when Hash
+ ask_hash
when Array
ask_array
end
end
@@ -148,7 +147,17 @@
colored_say "(number 1-#{@question.size})"
colored_say "? ", :no_newline => true
num = (@input.gets).to_i rescue colored_say("<red>Invalid input, must be a number between 1 and #{@question.size + 1}")
@answer = @question[num-1]
end
+
+ def ask_hash
+ @question.sort.each do |k,v|
+ colored_say("#{k}) #{v}")
+ end
+ colored_print((@opts[:prompt] || "> "))
+ pick = @input.gets.to_i
+ @answer = @question[pick]
+ end
+
end
end
\ No newline at end of file