Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

RubyTree

> 编程语言
Open source

A General Purpose Tree Data Structure for Ruby

391 stars0 likes0 views
WebsiteGitHub

About

A General Purpose Tree Data Structure for Ruby

RubyTree


bash
   /__\_   _| |__  _   _| |_ _ __ ___  ___
  / \// | | | '_ \| | | | __| '__/ _ \/ _ \
 / _  \ |_| | |_) | |_| | |_| | |  __/  __/
 \/ \_/\__,_|_.__/ \__, |\__|_|  \___|\___|
                  |___/

DESCRIPTION:

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.

WHAT'S NEW:

See History for the detailed Changelog.

See API-CHANGES for the detailed description of API level changes.

GETTING STARTED:

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.

REQUIREMENTS:

  • Ruby 2.7.x and above.

  • Run-time Dependencies:

    • JSON for converting to/from the JSON format
  • Development dependencies (not required for installing the gem):

    • Bundler for creating the stable build environment
    • Rake for building the package
    • Yard for the documentation
    • RSpec for additional Ruby Spec test files
    • Rubocop for linting the code

INSTALL:

To install the gem, run this command from a terminal/shell:

$ gem install rubytree

This should install the gem file for RubyTree. Note that you might need to have super-user privileges (root/sudo) to successfully install the gem.

DOCUMENTATION:

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::TreeNode

Documentation for the latest released version is available at:

rubytree.anupamsg.me/doc

Documentation for the latest git HEAD is available at:

rdoc.info/projects/evolve75/RubyTree

Note that the documentation is formatted using Yard.

DEVELOPERS:

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.

Using the git Repository

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 ssh

or

$ git clone https://github.com/evolve75/RubyTree.git  # using https

Setting up the Development Environment

RubyTree 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:package

These 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.

ACKNOWLEDGMENTS:

A big thanks to the following contributors for helping improve RubyTree:

  1. Dirk Breuer for contributing the JSON conversion code.
  2. Vincenzo Farruggia for contributing the (sub)tree cloning code.
  3. Eric Cline for the Rails JSON encoding fix.
  4. Darren Oakley for the tree merge methods.
  5. Youssef Rebahi-Gilbert for the code to check duplicate node names in the tree (globally unique names).
  6. Paul de Courcel for adding the postordered_each method.
  7. Jen Hamon for adding the from_hash method.
  8. Evan Sharp for adding the rename and rename_child methods.
  9. Aidan Steele for performance improvements to is_root? and node_depth.
  10. Marco Ziccadi for adding the path_as_string and path_as_array methods.
  11. John Mortlock for significant modernization of the library code and addition of Github workflows.
  12. Hermann Mayer for adding support for specialized tree nodes (sub-classes of Tree::TreeNode).
  13. Jakub Pavlik for fixing the creation of detached copies of unclonable objects such as :symbol, true|false, etc.
  14. bghalami-rc for updating the guard clause in the from_hash method.

LICENSE:

RubyTree is licensed under the terms of the BSD license. See LICENSE.md for details.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubydata-structuresrt-gemrubytraversal

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言