End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CSV::Row#dig
row.dig(index_or_header, *identifiers) → object
lib/csv/row.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/row.rb, line 715
def dig(index_or_header, *indexes)
value = field(index_or_header)
if value.nil?
nil
elsif indexes.empty?
value
else
unless value.respond_to?(:dig)
raise TypeError, "#{value.class} does not have \#dig method"
end
value.dig(*indexes)
end
end
Finds and returns the object in nested object that is specified by index_or_header and specifiers.
The nested objects may be instances of various classes. See Dig Methods.
Examples:
Example
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) row = table[0] row.dig(1) # => "0" row.dig('Value') # => "0" row.dig(5) # => nil