Skip to content

Instantly share code, notes, and snippets.

@k2works
Created December 24, 2014 02:44
Show Gist options
  • Save k2works/c31887791351d2fe8c18 to your computer and use it in GitHub Desktop.
Save k2works/c31887791351d2fe8c18 to your computer and use it in GitHub Desktop.
CSV読み込み時にコンバータを使用する
require 'csv'
converter = ->(field,field_info) {
if field_info.index == 1
field.upcase rescue field
else
field
end
}
p CSV.parse(%(foo,bar,baz), converters: converter ) # >> [["foo", "BAR", "baz"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment