适用于 Ruby 的通用树数据结构
/__\_ _| |__ _ _| |_ _ __ ___ ___
/ \// | | | '_ \| | | | __| '__/ _ \/ _ \
/ _ \ |_| | |_) | |_| | |_| | | __/ __/
\/ \_/\__,_|_.__/ \__, |\__|_| \___|\___|
|___/RubyTree is a pure Ruby implementation of the generic tree data structure. It provides a node-based model to store named nodes in the tree, and provides simple APIs to access, modify and traverse the structure.
The implementation is node-centric, where individual nodes in the tree are the primary structural elements. All common tree-traversal methods (pre-order, post-order, and breadth-first) are supported.
The library mixes in the Enumerable and Comparable modules to allow access to the tree as a standard collection (iteration, comparison, etc.).
A Binary tree is also provided, which provides the in-order traversal in addition to the other methods.
RubyTree supports importing from, and exporting to JSON, and also supports the Ruby's standard object marshaling.
This is a BSD licensed open source project, and is hosted at github.com/evolve75/RubyTree, and is available as a standard gem from rubygems.org/gems/rubytree.
The home page for RubyTree is at rubytree.anupamsg.me.
See History for the detailed Changelog.
See API-CHANGES for the detailed description of API level changes.
This is a basic usage example of the library to create and manipulate a tree. See the API documentation for more details.
…This example can also be found at examples/example_basic.rb.
Ruby 2.7.x and above.
Run-time Dependencies:
Development dependencies (not required for installing the gem):
To install the gem, run this command from a terminal/shell:
$ gem install rubytreeThis should install the gem file for RubyTree. Note that you might need to have super-user privileges (root/sudo) to successfully install the gem.
The primary class RubyTree is Tree::TreeNode. See the class documentation for an example of using the library.
If the ri documentation was generated during install, you can use this command at the terminal to view the text mode ri documentation:
$ ri Tree::TreeNodeDocumentation for the latest released version is available at:
Documentation for the latest git HEAD is available at:
rdoc.info/projects/evolve75/RubyTree
Note that the documentation is formatted using Yard.
This section is only for modifying RubyTree itself. It is not required for using the library!
You can download the latest released source code as a tar or zip file, as mentioned above in the installation section.
Alternatively, you can checkout the latest commit/revision from the Version Control System. Note that RubyTree's primary SCM is git and is hosted on github.com.
The git repository is available at github.com/evolve75/RubyTree.
For cloning the git repository, use one of the following commands:
$ git clone git://github.com/evolve75/RubyTree.git # using sshor
$ git clone https://github.com/evolve75/RubyTree.git # using httpsRubyTree uses Bundler to manage its dependencies. This allows for a simplified dependency management, for both run-time as well as during build.
After checking out the source, run:
$ gem install bundler
$ bundle install
$ bundle exec rake test:all
$ bundle exec rake doc:yard
$ bundle exec rake gem:packageThese steps will install any missing dependencies, run the tests/specs, generate the documentation, and finally generate the gem file.
Note that the documentation uses Yard, which will be downloaded and installed automatically by Bundler.
A big thanks to the following contributors for helping improve RubyTree:
postordered_each method.from_hash method.rename and
rename_child methods.is_root? and node_depth.path_as_string and
path_as_array methods.workflows.Tree::TreeNode).:symbol, true|false, etc.from_hash method.RubyTree is licensed under the terms of the BSD license. See LICENSE.md for details.
暂无开放 Issues,或尚未同步最近议题。