Sha256: b3aa942a8d93f8af4c26dca8f926058ae83192c13538e7c36330cc8cab86ff9b
Contents?: true
Size: 805 Bytes
Versions: 1
Compression:
Stored size: 805 Bytes
Contents
module MenuTxt module Node include ::Enumerable def initialize(name, url = '') @name, @url, @parent, @children, @level = name, url, nil, [], -1 end attr_reader :name, :url, :parent, :children, :level def leaf?; children.empty? end def traverse(&block) if block_given? yield(self) if parent children.each do |child| child.traverse(&block) end else enum_for end end alias_method :each, :traverse def add_child(name, url) self << self.class.new(name, url) end def <<(node) node.parent = self node.level = level + 1 children << node end protected def level=(int) @level = int end def parent=(node) @parent = node end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
menu_txt-0.1.0 | lib/menu_txt/node.rb |