
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Simple Ruby trees. Redwood is a simple implementation of a tree data structure in pure Ruby. It provides a few things:
redwood
command-line tool: like the Unix tree
tool, but in Ruby!gem install redwood
redwood
The redwood
command-line tool attempts a pure Ruby implementation of tree.
USAGE: redwood [ OPTIONS ] [ DIRECTORY ]
Looks a bit like this:
Redwood
|-- bin
| `-- redwood
|-- Gemfile
|-- lib
| |-- redwood
| | |-- filenode.rb
| | `-- node.rb
| `-- redwood.rb
|-- LICENSE
|-- pkg
| `-- redwood-0.0.1.gem
|-- Rakefile
|-- README.md
|-- redwood.gemspec
`-- test
|-- helper.rb
`-- test_redwood.rb
5 directories, 12 files
Help is a redwood --help
away. See also: redwood(1)
Redwood
The Redwood module is a module for including/extending tree-like features on your objects. It stores nodes in an Array. The only requirement for children is that they too include/extend tree-like features.
Methods include:
root? ## Is this a root node? Meaning, it has no parent.
leaf? ## Is this a leaf node? Meaning, is it without children?
root ## Get the root node in this tree.
children ## Get the children of this node.
siblings ## Get this nodes siblings.
only_child? ## Is this node without siblings?
has_children? ## Does this node have children?
ancestors ## All of the parent nodes of this node.
descendants ## All of the descendant nodes of this node.
depth ## Integer representing how deep this node is in the tree.
## A root node has a depth of 1, its children: 2, etc.
height ## The length of this node to its furthest descendant.
## A leaf node has a height of 1.
unlink ## Detach this node from its parent.
prune ## Unlink all of this node's chidren.
graft ## Add a node to this node's children.
walk ## Recursively yield every node in this tree to a block
view ## Make a fancy string representation of the tree
## as seen in the command-line tool
The Redwood::Node class is a simple implementation of the Redwood module. It is a good starting point for other trees. It adds new methods:
add_child(name) ## Add a child node. Nodes can have a #name.
[](name) ## Lookup children node by their #name.
<<(node) ## Alias for `graft`.
The Redwood::FileNode class is an example use-case for Redwood, and it powers the redwood
CLI. It stores a directory tree in a Redwood-backed structure. It has one primary method that does the magic:
dir = Redwood::FileNode.scandir '~/Projects/Redwood'
That will go through the directory and build a Redwood tree. Redwood::FileNode objects have methods that correspond to the File
class. So you can do things like dir.directory?
or dir.chmod
.
Now go forth and grow some Ruby-flavored trees.
Redwood is Copyright (c) 2010 Mark Wunsch and is licensed under the MIT License.
FAQs
Unknown package
We found that redwood demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.