开发者

How to visualize Hash data structure in ruby?

I have a hash object, whose structure looks similar to this:

{:category1 => 
 {:subcategory1 => 
  [ 
   {:article => "some article", :date =&g开发者_如何学编程t; "2010-04-04"},
   ...
  ],
  :subc2 => [...] 
 },
 :category2 => {...},
 ...
}

How can I visualize it as graph in ruby?

Is there a simple method/gem/lib that converts this Hash to DOT?


Why do you want it to be a graph? The data in your example is a tree.

You can see the tree easily in text with Ruby's pretty print:

pp my_hash

If you want a little cleaner output:

puts my_hash.to_yaml


I believe you could use the ruby-graphviz gem for this sort of visualization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜