File tree Expand file tree Collapse file tree 5 files changed +16
-5
lines changed
Expand file tree Collapse file tree 5 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 1313* Cycle prevention in ` add ` eliminates the earlier ` to_s ` /` size ` infinite-loop
1414 risk caused by cyclic graphs.
1515
16- * Add ` cmp ` for traversal/relationship-based comparison without changing the
16+ * Add ` cmp ` for traversal/relationship-based comparisons (` :each ` ,
17+ ` :breadth_each ` , ` :direct_or_sibling ` , ` :direct_only ` ) without changing the
1718 name-based ` <=> ` semantics.
1819
1920* Allow ` print_tree ` to write to a custom IO and add ` print_tree_to_s ` for
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ See the [API][rt_doc] documentation for more details.
7777
7878# ..... Example starts.
7979require ' tree' # Load the library
80+ require ' stringio'
8081
8182# ..... Create the root node first.
8283# ..... Note that every node has a name and an optional content payload.
@@ -92,8 +93,13 @@ root_node << Tree::TreeNode.new("CHILD2", "Child2 Content")
9293# ..... This is primarily used for debugging purposes.
9394root_node.print_tree
9495
96+ # ..... You can capture the output or request a formatted string.
97+ buffer = StringIO .new
98+ root_node.print_tree(io: buffer)
99+ output = root_node.print_tree_to_s
100+
95101# ..... Lets directly access children and grandchildren of the root.
96- # ..... The can be "chained" for a given path to any depth.
102+ # ..... These can be "chained" for a given path to any depth.
97103child1 = root_node[" CHILD1" ]
98104grand_child1 = root_node[" CHILD1" ][" GRANDCHILD1" ]
99105
@@ -136,6 +142,10 @@ This example can also be found at
136142 * [ RSpec] [ ] for additional Ruby Spec test files
137143 * [ RuboCop] [ ] for linting the code
138144
145+ Note: ` Tree::TreeNode.new ` accepts ` { checks: false } ` to disable validation
146+ guards in performance-critical code paths. This is risky and should only be
147+ used when benchmark data clearly justifies the risk.
148+
139149## INSTALL: ##
140150
141151To install the [ gem] [ rt_gem ] , run this command from a terminal/shell:
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ namespace :doc do # ................................ Documentation
6868 require 'rdoc/task'
6969 Rake ::RDocTask . new do |rdoc |
7070 rdoc . rdoc_dir = 'rdoc'
71- rdoc . title = "RubyTree Documenation : #{ PKG_NAME } -#{ PKG_VER } "
71+ rdoc . title = "RubyTree Documentation : #{ PKG_NAME } -#{ PKG_VER } "
7272 rdoc . main = 'README.md'
7373 rdoc . rdoc_files . include ( GEM_SPEC . extra_rdoc_files )
7474 rdoc . rdoc_files . include ( './lib/**/*.rb' )
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ module Tree
5353 # == TreeNode Class Description
5454 #
5555 # This class models the nodes for an *N-ary* tree data structure. The
56- # nodes are *named*, and have a place-holder for the node data (i.e.,
56+ # nodes are *named*, and have a placeholder for the node data (i.e.,
5757 # _content_ of the node). The node names are required to be *unique*
5858 # amongst the sibling/peer nodes. Note that the name is implicitly
5959 # used as an _ID_ within the data structure).
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ def as_json(_options = {})
7777 json_hash
7878 end
7979
80- # Creates a JSON representation of this node including all it's children.
80+ # Creates a JSON representation of this node including all its children.
8181 # This requires the JSON gem to be available, or else the operation fails with
8282 # a warning message. Uses the Hash output of #as_json method.
8383 #
You can’t perform that action at this time.
0 commit comments