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

select errors when provided a hash and a block #192

Open
steamwings opened this issue Jun 15, 2023 · 0 comments
Open

select errors when provided a hash and a block #192

steamwings opened this issue Jun 15, 2023 · 0 comments

Comments

@steamwings
Copy link

Greetings! This gem is extremely helpful--thanks for all the work on it! I will definitely open a PR for this issue if I can find the time, but I wanted to at least document this error.

Describe the problem

select works fine with (1) a hash of options but no block OR (2) with an array of options instead of a hash, but breaks with (3) a hash of values and a block.

Steps to reproduce the problem

# (1) just a hash, no block
pry(main)> TTY::Prompt.new.select("select thing", {a:2,b:3})
select thing a
=> 2

# (2) block provided, but not a hash of options
pry(main)> TTY::Prompt.new.select("select thing", [1,2,3]) do |q| puts 'hello'; end
hello
select thing 1
=> 1

# (3) hash of options and block 
pry(main)> TTY::Prompt.new.select("select thing", {a:2,b:3}) do |q| puts 'hello'; end
hello
NoMethodError: undefined method `+' for nil:NilClass

          @active = choices.index { |choice| !choice.disabled? } + 1
                                                                 ^
from .../.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/tty-prompt-0.23.1/lib/tty/prompt/list.rb:393:in `setup_defaults'

Actual behaviour

NoMethodError: undefined method `+' for nil:NilClass

(Notably, this is the same error that occurs if you pass an empty array or hash as your options.)

Expected behaviour

Allows user to select from provided options

Describe your environment

  • OS version: macOS Ventura 13.4
  • Ruby version: 3.1
  • TTY::Prompt version: 0.23.1
@steamwings steamwings changed the title select errors when provided a hash and a block select errors when provided a hash and a block Jun 15, 2023
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

No branches or pull requests

1 participant