Sha256: 21d1f2590a613ce167a6269bfdfb5d07c7bf0583c1ab49505cf32cb83d953ea8

Contents?: true

Size: 490 Bytes

Versions: 5

Compression:

Stored size: 490 Bytes

Contents

module RShade
  # nodoc
  class Tree
    attr_accessor :parent, :value
    attr_reader :nodes

    def initialize(value = nil)
      @value = value
      @nodes = []
      @parent = nil
    end

    def root?
      !parent
    end

    def <<(node)
      @nodes << node
    end

    def pre_order_traverse(depth = 0, &block)
      return unless block_given?

      yield(self, depth)
      nodes.each do |item|
        item.pre_order_traverse(depth + 1, &block)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rshade-0.1.6 lib/rshade/tree.rb
rshade-0.1.5 lib/rshade/tree.rb
rshade-0.1.4 lib/rshade/tree.rb
rshade-0.1.3 lib/rshade/tree.rb
rshade-0.1.2 lib/rshade/tree.rb