How is mutation done in Ruby for this:
row = row.to_hash
I've tried row.to_hash!
But it doesn't work.
EDIT: Here is the code where it's in:
CSV.foreach('stores.csv', :headers => true) do |row|
row = row.to_hash
end
How is mutation done in Ruby for this:
row = row.to_hash
I've tried row.to_hash!
But it doesn't work.
EDIT: Here is the code where it's in:
CSV.foreach('stores.csv', :headers => true) do |row|
row = row.to_hash
end
Unless I misunderstand your question you might try:
rows = []
CSV.foreach('stores.csv', :headers => true) do |row|
rows << row.to_hash
end
It's not actually mutation, but it does give you the output you seem to be looking for. One of the reasons for having separate methods for performing an action for new output vs. changing data in place is that in general it is wiser to have your input data be immutable. Reading from a CSV file probably doesn't fit into this paradigm cleanly (the original input is in a file somewhere), which is likely why there's no ! version of to_hash.
Optionally in my above code you could just process the hash and put the results where you want it if the input file is humongous in order to save space, rather than just shoving all the hashes into the array and then processing that array.
We actually can't say if there is such a method. But it's most likely there isn't one, if you get a NoMethodError. :)
FlashHash class. I don't think you're using that one.