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 8430353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:47+00:00 2026-06-10T05:34:47+00:00

I have a nested hash like :- profile: status: nil: 3 x: 2 priority:

  • 0

I have a nested hash like :-

profile:
  status:                               
     nil: 3    
     x: 2   

  priority:
     x: 2
     y: 2

Is there a way of setting the default value for status like:-

profile:
  status:
    default:0
    nil: 3
    x:2

I dont want solutions like these or any other method :-

h = Hash.new("Go Fish")
h.default = "Go fish"

coz I have a yml file loaded with configs hash and other mapping hashes, like the status, priority mapping above. So my script extracts the configs as well as the other hash values from these yml and use them. Now for the status and priority mapping, I need this status and priority subhash to return a value if it doesnt find any matching symbol(i.e,. if no such mapping exists) inside this hash. I can set that default value in the code using the other methods. But the whole point is I want any layman to edit this yml and be able run my script. Hence I want the default values to be set here.

  • 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-06-10T05:34:48+00:00Added an answer on June 10, 2026 at 5:34 am

    Since none seem to come up with an alternative, for now I have resorted to this method.

     profile:
      status:
       default: 'x' number
       one: 1
       two: 2
       three: 3
    

    in the code

      profile['status'].default=priority['status']['default']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large hash with nested arrays and hashes. I would like to
I have a nested hash table that looks like this: my %myhash = (
I have a nested hash table. If i write json.each{|key, value| puts value; puts;
I have many levels of a nested hash like: { :foo => 'bar', :foo1
I am trying to work with a nested hash. I have a deck of
I have nested iframes and I would like to use onload function for the
What if I have nested loops, and I want to break out of all
I'm using Devise and have models set up like this: User has_one :profile Profile
I have nested dictionaries: {'key0': {'attrs': {'entity': 'p', 'hash': '34nj3h43b4n3', 'id': '4130'}, u'key1': {'attrs':
Suppose we have a nested hash here. a = {:0 => {:CA => {:count

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.