class Sycamore::NothingTree
The Nothing Tree
singleton class.
The Nothing Tree
is an empty Sycamore
Tree
, and means “there are no nodes”.
It is immutable:
-
{Tree::QUERY_METHODS Query method} calls will behave like a normal, empty
Tree
. -
{Tree::DESTRUCTIVE_COMMAND_METHODS Pure destructive command} calls, will be ignored, i.e. being no-ops.
-
But all other {Tree::COMMAND_METHODS 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 {#existent?}.
Constants
- NestedString
@api private
Public Instance Methods
Try to emulate a falsey value, by negating to true
.
@return [Boolean] true
@see devblog.avdi.org/2011/05/30/null-objects-and-falsiness/
# File lib/sycamore/nothing.rb, line 114 def ! true end
Checks if the given object is an empty tree.
@return [Boolean]
# File lib/sycamore/nothing.rb, line 94 def ==(other) (other.is_a?(Tree) or other.is_a?(Absence)) and other.empty? end
(see Tree#absent?
)
# File lib/sycamore/nothing.rb, line 35 def absent? true end
# File lib/sycamore/nothing.rb, line 55 def child_of(node) self end
# File lib/sycamore/nothing.rb, line 81 def freeze super end
A developer-friendly string representation of the Nothing tree.
@return [String]
# File lib/sycamore/nothing.rb, line 77 def inspect '#<Sycamore::Nothing>' end
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.
# File lib/sycamore/nothing.rb, line 132 def like?(object) object.nil? or object.equal? self end
(see Tree#nothing?
)
# File lib/sycamore/nothing.rb, line 28 def nothing? true end
# File lib/sycamore/nothing.rb, line 59 def to_native_object(sleaf_child_as: nil, **args) sleaf_child_as end
A string representation of the Nothing tree.
@return [String]
# File lib/sycamore/nothing.rb, line 68 def to_s 'Tree[Nothing]' end