Skip to content

row access method(like .first, .count, .map) remove row unintentionally #261

@tktk0430

Description

@tktk0430

https://paiza.io/projects/UZG89oyrPr2fhhw51QKH0A

require 'csv'

raw =<<~EOF
  name,age
  tom,13
  bob,14
  alice,15
EOF

csv = CSV.new(raw, headers: true)
puts csv.count #=> expect 3, and result is 3
puts csv.count #=> expect 3, but result is 0

csv = CSV.new(raw, headers: true)
puts csv.first['name'] #=> expect tom, and result is tom
puts csv.first['name'] #=> expect tom, but result is bob
puts csv.first['name'] #=> expect tom, but result is alice

In my sense, .count and .first is not destructive, but these method change csv instance data.
What shoud I do to get result I expect.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions