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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:49:18+00:00 2026-06-10T21:49:18+00:00

I like method shown here – https://stackoverflow.com/a/9648410/1646893 and I want to use it in

  • 0

I like method shown here – https://stackoverflow.com/a/9648410/1646893 and I want to use it in my case.
What if we have something like this:

{"a"=>{"b"=>"111", "c"=>"9", "d"=>{"ff"=>{"uu"=>[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"67"}, "j"=>{"@l"=>"45"}}]}, "@e"=>"56"}, "@b1"=>"01", "@b2"=>"02", "@b3"=>"03"}}

And When I tried to use our method:

{["a", "b"]=>"111", ["a", "c"]=>"9", ["a", "d", "ff", "uu"]=>[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"67"}, "j"=>{"@l"=>"45"}}], ["a", "d", "@e"]=>"56", ["a", "@b1"]=>"01", ["a", "@b2"]=>"02", ["a", "@b3"]=>"03"}

The result was an array with 2 values:

[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}]

This is what i want to get:

["a", "d", "ff", "uu", "q0", "w0", "j0", "@l0"]=>"44"

etc.

Maybe I should change key names before using flat_hash method?
What should i do to have the result without an array and key names contain?

  • 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-10T21:49:19+00:00Added an answer on June 10, 2026 at 9:49 pm

    Here’s my answer that produces what I believe is a better output that what you are asking for. If you absolutely desperately need exactly the output you have asked for, say so and perhaps I’ll provide a variation that produces it.

    class Hash;  def each_with_key; each{ |k,v|            yield(v,k) }; end; end
    class Array; def each_with_key; each.with_index{ |v,i| yield(v,i) }; end; end
    
    def path_to_values(hash)
      {}.tap do |result|
        crawl = ->(o,chain=[]) do
          o.each_with_key do |v,k|
            path = chain + [k]
            (v.is_a?(Hash) || v.is_a?(Array)) ? crawl[v,path] : result[path] = v
          end
        end
        crawl[hash]
      end
    end
    

    Seen in action:

    h = {
      "a" => {
        "b"=>"111", "c"=>"9",
        "d"=>{
          "ff"=>{
            "uu"=>[
              { "q"=>"77",
                "r"=>{"w"=>"66"},
                "j"=>{"@l"=>"44"}},
              { "q"=>"78",
                "r"=>{"w"=>"67"},
                "j"=>{"@l"=>"45"}}
            ]
          },
          "@e"=>"56"
        },
        "@b1"=>"01", "@b2"=>"02", "@b3"=>"03"
      }
    }
    require 'pp'
    pp path_to_values(h)
    #=> {["a", "b"]=>"111",
    #=>  ["a", "c"]=>"9",
    #=>  ["a", "d", "ff", "uu", 0, "q"]=>"77",
    #=>  ["a", "d", "ff", "uu", 0, "r", "w"]=>"66",
    #=>  ["a", "d", "ff", "uu", 0, "j", "@l"]=>"44",
    #=>  ["a", "d", "ff", "uu", 1, "q"]=>"78",
    #=>  ["a", "d", "ff", "uu", 1, "r", "w"]=>"67",
    #=>  ["a", "d", "ff", "uu", 1, "j", "@l"]=>"45",
    #=>  ["a", "d", "@e"]=>"56",
    #=>  ["a", "@b1"]=>"01",
    #=>  ["a", "@b2"]=>"02",
    #=>  ["a", "@b3"]=>"03"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method like this, public List<T> Test<T>() { // do something. }
I'm trying to make modal frame in Java Applet such like shown here: http://www.java2s.com/Tutorial/Java/0240__Swing/Showthegivenframeasmodaltothespecifiedowner.htm
I have a method like so private bool VerbMethod(string httpVerb, string methodName, string url,
I want a method like this: public async void DoSomething() { DoSomethingElse(); } But
i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table
I have an SPList event receiver method like: ItemDeleting(ByVal voHttpContex As HttpContext, ByVal voProperties
I followed the simple method described here and have a DataGrid with dynamically generated
I would like to recreate the background gradient shown here on my web page.
I have a css transform that happens when a button is clicked shown here
suppose I have simple C# code to print HELLO WORLD as shown in here

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.