Skip to content

Instantly share code, notes, and snippets.

@aharpole
Last active August 29, 2015 14:00
Show Gist options
  • Save aharpole/11385660 to your computer and use it in GitHub Desktop.
Save aharpole/11385660 to your computer and use it in GitHub Desktop.
CSV.parse unexpected behavior
1.9.3-p545 :002 > headers = "col,is,cool"
=> "col,is,cool"
1.9.3-p545 :003 > csv = CSV.parse(headers,{headers:true})
=> #<CSV::Table mode:col_or_row row_count:1>
1.9.3-p545 :004 > tworows = "#{headers}\nabc,def,ghi"
=> "col,is,cool\nabc,def,ghi"
1.9.3-p545 :005 > other_csv = CSV.parse(tworows,{headers:true})
=> #<CSV::Table mode:col_or_row row_count:2>
1.9.3-p545 :006 > csv.headers
=> [] #I expect this to be ["col", "is", "cool"]
1.9.3-p545 :007 > other_csv.headers
=> ["col", "is", "cool"] #this is what I expect it to be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment