Я собираю данные с espn.com о всех игроках воинов Золотого штата и хочу показать каждый атрибут каждого игрока.Такие как их рост должности, зарплата и колледж.Однажды я даю пользователю возможность выбрать игрока, о котором он хотел бы узнать больше.Я хотел бы, чтобы эта информация была видна пользователю, но в процессе я вижу ошибку.
Это код, который я написал.
attr_accessor :player, :continue
def intialize
@continue = true
end
def call
start
#skips over while loop
#while @continue
list_players
menu
show_player if @continue == true && @player != nil
#end
goodbye
end
def start
puts "Welcome to the Golden State Roster 'The Home Of The Splash Brothers'"
end
def goodbye
puts "See you next time for any players updates!"
end
def list_players
Player.all.clear
Scraper.scrape_page
Player.all.each.with_index(1) do |player, index|
puts "#{index}. #{player.name}"
end
end
def menu
input = ""
while input != "exit"
puts "Choose any player you wish by the 'number', type 'list' to reshow list or type 'exit' when finished."
input = gets.strip.downcase
if input.to_i > 0
the_player = @player[input.to_i - 1]
puts "#{the_player.name} plays #{the_player.position} for the Golden State Warriors. He is #{the_player.age} years old and #{the_player.height} tall. He comes in weighing #{the_player.weight}. #{the_player.name} graduated from #{the_player.college} and makes honest living of #{the_player.salary} dollars per year."
"Select another player by typing 'yes' or press 'exit' when you're ready to leave."
binding.pry
elsif input == "exit"
@continue = false
# elsif input.to_i.between?(1, Player.all.length)
# @player = Player.all[input.to_i - 1]
elsif input == "list"
list_players
else
puts "Error, Choose any player you wish by the number or type 'exit' when finished."
end
end
end ```
It breaks at "the_player"
```This is the error
```Welcome to the Golden State Roster 'The Home Of The Splash Brothers'
1. Jordan Bell
2. Andrew Bogut
3. Quinn Cook
4. DeMarcus Cousins
5. Stephen Curry
6. Marcus Derrickson
7. Kevin Durant
8. Jacob Evans
9. Draymond Green
10. Andre Iguodala
11. Jonas Jerebko
12. Damian Jones
13. Damion Lee
14. Shaun Livingston
15. Kevon Looney
16. Alfonzo McKinnie
17. Klay Thompson
Choose any player you wish by the 'number', type 'list' to reshow list or type 'exit' when finished.
4
Traceback (most recent call last):
2: from ./bin/ballers:6:in `<main>'
1: from /home/Thisforbliss/Development/project/lib/project/cli.rb:17:in`call'
/home/Thisforbliss/Development/project/lib/project/cli.rb:45:in `menu': undefined method `[]' for nil:NilClass (NoMethodError)```