Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeat_entry.rb example's hash gather repeats the original question twice, not using elements of the hash #87

Closed
daniel-ferguson opened this issue Jul 3, 2013 · 3 comments · Fixed by #88

Comments

@daniel-ferguson
Copy link
Contributor

Cut down code from examples/repeat_entry.rb

require 'rubygems'
require 'highline/import'
pass = ask("Enter your password:  ") do |q|
  q.echo = '*'
  q.verify_match = true
  q.gather = {"Enter a password" => '',
              "Please type it again for verification" => ''}
end

response from terminal:

Enter your password:  ****
// I expected: "Enter a password: "
Enter your password:  ****      
// I expected: "Please type it again for verification: "
Your password is now asdf!

I feel like I might be missing something in terms of usage that isn't correctly illustrated by the example.

@JEG2
Copy link
Owner

JEG2 commented Jul 3, 2013

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.

@daniel-ferguson
Copy link
Contributor Author

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.

@JEG2
Copy link
Owner

JEG2 commented Jul 4, 2013

I think you are right and I am wrong. It looks like this is a bug. It's not working as it should. 😦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants