CSV to Multidimensional Array cannot catch in the loop a specific column and use method .include?

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”]]


if array[i][1].downcase().include?(option.downcase())

puts "#{array[i][1]}"


OUTPUT=> example

but if i have a a file.csv:

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"])



  if @players[i][1].downcase().include?(playername.downcase())

    puts "#Found: {@players[i][1]}"




name = gets.chomp


… > 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs