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.1 release

Version 2.2.1 released on July 24, 2026.

  • Bump the json runtime dependency to 2.19.9+, fixing a heap buffer overflow when generating to a streamed IO (CVE-2026-54696).
See the the Changelog for details.

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.1
$ 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 can import from and export to JSON and supports Ruby object marshaling.
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.1). 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.