Closed daniel-ferguson closed 11 years ago
The example is a little odd. The question is ignored when gather with a Hash is used. See the description of gather in the RDoc.
Mmmm.. That's what I expected. I've had a look at that already.
"Optionally gather can be set to a Hash. In this case, the question will be asked once for each key and the answers will be returned in a Hash, mapped by key. The @key variable is set before each question is evaluated, so you can use it in your question."
And the code below makes me think that I should ask() differently if I'm using a hash. Though it seems that it's locked into asking the original question, however many times.
# /lib/highline.rb
# lines: 783 - 790
when Hash
@answers = { }
@gather.keys.sort.each do |key|
@question = original_question
@key = key
@answers[key] = ask(@question)
end
Is it possible that you could give me a super simple example of gather working with a hash, I'm not familiar with highline yet and the RDoc entry didn't lead me to a working solution. I'm sure it's something simple. Thank you.
I think you are right and I am wrong. It looks like this is a bug. It's not working as it should. :frowning:
Cut down code from examples/repeat_entry.rb
response from terminal:
I feel like I might be missing something in terms of usage that isn't correctly illustrated by the example.