Hi All
this is my code which works perfectly if i declare an array.
option = “EXA”
array = [[1, “example”, “wahtever”], [1, “wahtever”, “else”], [1,
“grail”, “holy”]]
array.each_index{|i|
if array[i][1].downcase().include?(option.downcase())
puts "#{array[i][1]}"
end
OUTPUT=> example
but if i have a a file.csv:
id,player,team
1,Francesco Totti, Roma
2,Roberto Baggio, retired
3,Paolo Maldini, grandpa
require ‘Player’
require ‘csv’
players_csv = “./palyers.csv”
def search_player (players_csv,playername)
CSV.foreach(players_csv, headers: true) do |row|
#Another Class Player initializes with id , player and team
# storing the csv reader into an array named @players
@players << Player.new(row["id"], row["player"],row["team"])
end
@players.each_index{|i|
if @players[i][1].downcase().include?(playername.downcase())
puts "#Found: {@players[i][1]}"
end
}
end
name = gets.chomp
search_player(players_csv,name)
… > FrAnC
i should get
Found: Francesco Totti
but i get this Error… that [] cannot be transformed into an
Integer… on the line
@players << Player.new(row[“id”], row[“player”],row[“team”])
is this completely wrong???
i do not undersand
both example i am dealing with Arrays first works seconds does not