#we know that way to create hash_in_hash
h=Hash.new{ |h,k| h[k]=Hash.new(&h.default_proc) } #it reduce time to create both internal and external hashes. #consider, hash={h1=>{h1h=>{w1=>k1,w2=>k2,..}},..,h5=>{h5h=>{..}} #how can I iterate this hash? expecting easy way like second_line.
#we know that way to create hash_in_hash
h=Hash.new{ |h,k| h[k]=Hash.new(&h.default_proc) } #it reduce time to create both internal and external hashes. #consider, hash={h1=>{h1h=>{w1=>k1,w2=>k2,..}},..,h5=>{h5h=>{..}} #how can I iterate this hash? expecting easy way like second_line.
Is this a poem?
···
On Fri, Dec 20, 2013 at 1:41 AM, selvag selvag <lists@ruby-forum.com> wrote:
I'm not understand well.
Could you give an example of a hash and how you want to iterate
through it (the results you are expecting)?
I'm asking this because to iterate through a Hash of this kind is
similar to a tree.
And when you iterate through a tree, there's more than a way to do it
and sometimes people want to:
- get track of (what is) the current depth,
- the parent nodes of the current node,
- what would be the return value for current node after iterating
through the children nodes,
- what should it be yield to the block? A (sub)tree of the childrens?
A return value? A return value of the children AND the current node?
- and things like that.
Abinoam Jr.
···
On Fri, Dec 20, 2013 at 4:41 AM, selvag selvag <lists@ruby-forum.com> wrote:
#we know that way to create hash_in_hash
h=Hash.new{ |h,k| h[k]=Hash.new(&h.default_proc) } #it reduce time to create both internal and external hashes. #consider, hash={h1=>{h1h=>{w1=>k1,w2=>k2,..}},..,h5=>{h5h=>{..}} #how can I iterate this hash? expecting easy way like second_line.
consider this inheritance, where parent hash contains more user_id
each user_id has more date_id and each date_id has only one hash (name
may be "item_list".
That is,