End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CSV#header_convert
header_convert(name = nil, &converter)
lib/csv.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/csv.rb, line 2508
def header_convert(name = nil, &converter)
header_fields_converter.add_converter(name, &converter)
end
The block need not return a String object:
Example
csv = CSV.open(path, headers: true) csv.header_convert {|header, field_info| header.to_sym } table = csv.read table.headers # => [:Name, :Value]
If converter_name is given, the block is not called:
Example
csv = CSV.open(path, headers: true) csv.header_convert(:downcase) {|header, field_info| fail 'Cannot happen' } table = csv.read table.headers # => ["name", "value"]
Raises a parse-time exception if converter_name is not the name of a built-in field converter:
Example
csv = CSV.open(path, headers: true) csv.header_convert(:nosuch) # Raises NoMethodError (undefined method `arity' for nil:NilClass) csv.read