Skip to content

End of Life Ruby 3.2 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

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
See also #delete_if #each #delete #each_pair also in 3.3 · 3.1 · 3.0