Sha256: a1d69e88130a6efc64c539b5f917843a52800d0e48e89420ec045d37b98f75ca

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

= BasicTree

A basic Ruby tree structure with nice syntax.

== Example

  fruit = BasicTree.new "Fruit" do
    add "Apple" do
      add "Red Delicious"
    end
    add "Banana" do
      add "Manzano"
      add "Plantain"
    end
    add "Orange"
  end

  fruit.object
  # "Fruit"

  banana = fruit.get(2) # get the 2nd fruit
  banana.object # "Banana"

  plantain = banana.get(2) # get the 2nd banana
  plantain.object # "Plantain"

  plantain.parent.object # "Banana"

  plantain.path.map(&:object)
  # ["Fruit", "Banana", "Plantain"]

  plantain.ancestors.map(&:object) # ancestors is like path except it doesn't include itself
  # ["Fruit", "Banana"]

  banana.subtree.map(&:object)
  # ["Banana", "Manzano", "Plantain"]

  fruit.descendants.map(&:object) # descendants is like subtree except it doesn't include itself
  # ["Apple", "Red Delicious", "Banana", "Manzano", "Plantain", "Orange"]

  banana.siblings.map(&:object)
  # ["Apple", "Orange"]

  plantain.root.object # "Fruit"

  plantain.level # 3

  banana.root? # false

  fruit.root? # true

  banana.leaf? # false

  plantain.leaf? # true

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

See LICENSE for details.

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basic_tree-1.0.3 README.rdoc
basic_tree-1.0.2 README.rdoc
basic_tree-1.0.1 README.rdoc