木構造
こんな感じかな。
class Tree attr_reader :root, :childs, :data def initialize(data, root=nil) @root = root @data = data @childs = [] end def addNode(data) @childs << Tree.new(data,self) end def addNodes(ary_data) ary_data.each do |l| addNode(l) end end end tree = Tree.new("Animal") tree.addNodes(["Human","Cat","Dog"]) puts "root:", tree.data puts "childs:" tree.childs.each do |node| puts node.data end