Skip to content

Commit 4e4003a

Browse files
committed
Refine documentation examples
Fix minor wording issues, document print_tree output helpers in README, and clarify cmp policy coverage in History.
1 parent ca04e03 commit 4e4003a

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

History.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
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

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ See the [API][rt_doc] documentation for more details.
7777

7878
# ..... Example starts.
7979
require '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.
9394
root_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.
97103
child1 = root_node["CHILD1"]
98104
grand_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

141151
To install the [gem][rt_gem], run this command from a terminal/shell:

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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')

lib/tree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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).

lib/tree/utils/json_converter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
#

0 commit comments

Comments
 (0)