D
D
Demigodd2019-05-03 11:43:37
Ruby on Rails
Demigodd, 2019-05-03 11:43:37

How to parse hashes in Ruby?

Repl example .
How to walk through the entire hash with nestings in Ruby, preferably without recursions.
In the example from Repl.it, who has show equal to true , he is taken.
You also need to look at the show value of children .
But if the object has a child, then it is excluded from the selection. But his chil's are not.
For example, there is such a hash.

{
  "aaa"=>{"show"=>true},
  "bbb"=>{"show"=>false},
  "ccc"=>{
    "show"=>true,
    "child"=>{
      "child_1"=>{"show"=>true},
      "child_2"=>{"show"=>false}
    }
  },
  "ddd"=>{"show"=>false}
}

You need to parse it so that in the end you get this.
{:aaa=>123, :child_1=>123}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alfss, 2019-05-03
@Demigodd

If the maximum nesting level is not known, then there is no way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question