Class: Sycamore::NothingTree
- Includes:
- Singleton
- Defined in:
- lib/sycamore/nothing.rb
Overview
The Nothing Tree singleton class.
The Nothing Tree is an empty Sycamore Tree, and means “there are no nodes”.
It is immutable:
-
Query method calls will behave like a normal, empty Tree.
-
Pure destructive command calls, will be ignored, i.e. being no-ops.
-
But all other command calls, will raise a NothingMutation.
It is the only Tree object that will return true
on a #nothing? call. But like Absence, it will return true
on #absent? and false
on Tree#existent?.
Defined Under Namespace
Classes: NestedStringPresentation
Constant Summary collapse
- NestedString =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
NestedStringPresentation.instance.freeze
Constants inherited from Tree
Tree::ADDITIVE_COMMAND_METHODS, Tree::COMMAND_METHODS, Tree::DESTRUCTIVE_COMMAND_METHODS, Tree::PREDICATE_METHODS, Tree::PURE_ADDITIVE_COMMAND_METHODS, Tree::PURE_DESTRUCTIVE_COMMAND_METHODS, Tree::QUERY_METHODS
Instance Attribute Summary
Attributes inherited from Tree
Instance Method Summary collapse
-
#! ⇒ Boolean
Try to emulate a falsey value, by negating to
true
. -
#==(other) ⇒ Boolean
Checks if the given object is an empty tree.
- #absent? ⇒ Boolean
- #child_of(node) ⇒ Object
- #freeze ⇒ Object
-
#inspect ⇒ String
A developer-friendly string representation of the Nothing tree.
-
#like?(object) ⇒ Boolean
Some helpers.
-
#nothing? ⇒ Boolean
Checks if this is the Nothing tree.
- #to_native_object(sleaf_child_as: nil, **args) ⇒ Object
-
#to_s ⇒ String
A string representation of the Nothing tree.
Methods inherited from Tree
#<, #<=, #>, #>=, #[]=, #_search, #add, #add_child, #add_node, #add_node_with_empty_child, #add_path, #add_tree, #child_at, #clear, #clear_child_of_node, #clear_data, #compact, #delete, #delete_node, #delete_path, #delete_tree, #dup, #each_node, #each_pair, #each_path, #empty?, #eql?, #existent?, #external?, #fetch, #fetch_path, #hash, #height, #include?, #include_node?, #include_path?, #initialize, #initialize_clone, #internal?, #leaf?, #matches?, #matches_atom?, #matches_enumerable?, #matches_tree?, #new_child, #node, #node!, #nodes, #present?, #replace, #search, #size, #strict_leaf?, #strict_leaves?, #to_h, #total_size, tree_like?, #valid_node!, #valid_node_element!, #valid_tree!, with
Constructor Details
This class inherits a constructor from Sycamore::Tree
Instance Method Details
#! ⇒ Boolean
Try to emulate a falsey value, by negating to true
.
112 113 114 |
# File 'lib/sycamore/nothing.rb', line 112 def ! true end |
#==(other) ⇒ Boolean
Checks if the given object is an empty tree.
93 94 95 |
# File 'lib/sycamore/nothing.rb', line 93 def ==(other) (other.is_a?(Tree) or other.is_a?(Absence)) and other.empty? end |
#absent? ⇒ Boolean
Checks if this is an unresolved Absence or Sycamore::Nothing.
34 35 36 |
# File 'lib/sycamore/nothing.rb', line 34 def absent? true end |
#child_of(node) ⇒ Object
54 55 56 |
# File 'lib/sycamore/nothing.rb', line 54 def child_of(node) self end |
#freeze ⇒ Object
80 81 82 |
# File 'lib/sycamore/nothing.rb', line 80 def freeze super end |
#inspect ⇒ String
A developer-friendly string representation of the Nothing tree.
76 77 78 |
# File 'lib/sycamore/nothing.rb', line 76 def inspect "#<Sycamore::Nothing>" end |
#like?(object) ⇒ Boolean
Some helpers
Ideally these would be implemented with Refinements, but since they aren’t available anywhere (I’m looking at you, JRuby), we have to be content with this.
129 130 131 |
# File 'lib/sycamore/nothing.rb', line 129 def like?(object) object.nil? or object.equal? self end |
#nothing? ⇒ Boolean
Checks if this is the Sycamore::Nothing tree.
27 28 29 |
# File 'lib/sycamore/nothing.rb', line 27 def nothing? true end |
#to_native_object(sleaf_child_as: nil, **args) ⇒ Object
58 59 60 |
# File 'lib/sycamore/nothing.rb', line 58 def to_native_object(sleaf_child_as: nil, **args) sleaf_child_as end |
#to_s ⇒ String
A string representation of the Nothing tree.
67 68 69 |
# File 'lib/sycamore/nothing.rb', line 67 def to_s "Tree[Nothing]" end |