Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:04:55+00:00 2026-05-26T14:04:55+00:00

How is mutation done in Ruby for this: row = row.to_hash I’ve tried row.to_hash!

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:04:55+00:00Added an answer on May 26, 2026 at 2:04 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code posted here is 'example' code, it's not production code. I've done this
I am trying to construct equivalent of this code in JSF2 <form action=/search.xhtml method=get>
I am attempting to write some simple code in F#, and i get this
I have this simple example code: var request = mozIndexedDB.open('MyTestDatabase'); request.onsuccess = function(event){ var
With reference to the following link: http://docs.python.org/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe I wanted to know if the following:
Some Genetic Algorithm frameworks, such as http://www.aforgenet.com/ requires many parameters, such as mutation rate,
Is it harder (or impossible) to implement mutation testing in some languages than others?
In the past few years I've mostly done UI development in Eclipse, which is
I am considering using an NSMutableDictionary in place of my current NSMutableArray. This is
I'm doing some work with Genetic Algorithms and want to write my own GA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.