What is RubyTree?
RubyTree is a simple and general purpose implementation of the Tree data structure for the Ruby language. RubyTree provides a clean, node-based model for building hierarchical structures (menus, file systems, org charts, parse trees) with predictable traversal and modification APIs. The library emphasizes clarity and correctness, while staying flexible enough to adapt to specialized tree variants in your own code.
Use RubyTree when you need explicit parent/child relationships, named nodes, or a simple way to walk and transform hierarchies. The core API is intentionally small, and the library is designed to be easy to read and extend.
The current version provides implementations of:
- A general purpose node-based tree data structure, and
- A binary tree.
RubyTree is available as a rubygem and is released under the BSD-2-Clause License.
What's New? R2.2.3 release
Version 2.2.3 released on October 7, 2026.
- Add support for the JSON gem 3.x while retaining compatibility with 2.x.
- Use
Tree::TreeNode.from_jsonto rebuild trees from JSON documents.
Getting Started
Installing RubyTree
Download & install the latest version using rubygem (you may need to do this with admin rights):
$ gem install rubytree -v 2.2.3
$ gem update rubytree
Check the documentation for RubyTree by looking up the RDoc using ri, or by browsing the online documentation.
$ ri Tree::TreeNode
Quick Start
root = Tree::TreeNode.new("root", "Root")
root << Tree::TreeNode.new("child", "Child")
root.each { |node| puts node.name }
FAQ
- What is RubyTree?
- RubyTree is a Ruby implementation of a generic tree data structure with named nodes, traversal helpers, and a binary tree variant.
- Does RubyTree support JSON or marshaling?
- Yes. RubyTree supports JSON 2.x and 3.x. Use
Tree::TreeNode.from_jsonto rebuild trees, and Ruby object marshaling is also supported. - What is the primary class?
- The primary class is
Tree::TreeNode. - What Ruby versions are supported?
- Ruby 2.7+ (current release).
Support & Security
Supported versions: the latest release (2.2.3). Older releases are best-effort. For support, please use the GitHub issue tracker.
Contributing to RubyTree
Help RubyTree with your suggestions, bug reports, or patches and pull requests.