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

  • SEARCH
  • Home
  • 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 7509481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:55:50+00:00 2026-05-29T22:55:50+00:00

I want to merge a value into a Thor option hash . If I

  • 0

I want to merge a value into a Thor option hash.

If I just use merge I get an error, HashWithIndifferentAccess

I have read the documentation but I have difficulties to understand how to get it to work. I guess I hope this question will help me to both find an answer on the question how to merge a value into this kind of hash and understand how to read documentation.

p options.inspect 
#=> "{\"ruby\"=>\"/Users/work/.rbenv/versions/1.9.2-p290/bin/ruby\"}"
p options.merge!(:a => true)
#=> hash_with_indifferent_access.rb:26:in `[]=': can't modify frozen hash (RuntimeError)
  • 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-29T22:55:51+00:00Added an answer on May 29, 2026 at 10:55 pm

    The hash is frozen:

    “Prevents further modifications to obj. A RuntimeError will be raised
    if modification is attempted. There is no way to unfreeze a frozen
    object.”

    You can copy options to a new hash (will be unfrozen) and modifying that instead.

    new_options = options.dup
    options = new_options
    options.merge!(:a => "this will work now")
    

    Or if you want it to be even briefer:

    options=options.dup
    options.merge!(:a => "this will work now")
    

    The Thor library returns a frozen hash by default, so another option would be to modify the library to return unfrozen hashes, but I think the first solution is good enough.

    Below is a link to the source code for Thor’s parse function, you’ll notice it freezes the “assigns” return hash prior to actually returning it (go to the bottom of the page, and under (Object) parse(args), click ‘View Source’. The freezing is on line 83 of the source snippet.)

    http://rubydoc.info/github/wycats/thor/master/Thor/Options

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

Sidebar

Related Questions

I have 2 images and I want to merge them into one on my
I have a list of List<KeyvaluePair<DateTime, int>> , which I want to merge into
I have 2 arrays that I want to merge based on a key's value
I have 8 bool variables, and I want to merge them into a byte.
I want to merge this queries into only one, to return 2 values (scount_atp
I want to merge two branches that have been separated for a while and
I want to merge data. Following are my MySQL tables. I want to use
I have to array and I want to merge this two array with a
I have two objects and I want to merge them: public class Foo {
i want to merge two datagridview columns into one new column. i first change

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.