Skip to content

Instantly share code, notes, and snippets.

View ngm's full-sized avatar
🙂

Neil M ngm

🙂
View GitHub Profile
@ngm
ngm / tree_hash.rb
Created November 27, 2011 12:42
Seven Languages in Seven Weeks - Ruby - Day 2 - Tree
class Tree
attr_accessor :children, :node_name, :depth
def initialize(structure, depth)
@node_name = structure.keys.first
@depth = depth
@children = structure.values.first.map { |name,child| Tree.new({name,child}, depth+1) }
end