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:

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

!() click to toggle source

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
==(other) click to toggle source

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
absent?() click to toggle source

(see Tree#absent?)

# File lib/sycamore/nothing.rb, line 35
def absent?
  true
end
child_of(node) click to toggle source
# File lib/sycamore/nothing.rb, line 55
def child_of(node)
  self
end
freeze() click to toggle source
Calls superclass method
# File lib/sycamore/nothing.rb, line 81
def freeze
  super
end
inspect() click to toggle source

A developer-friendly string representation of the Nothing tree.

@return [String]

# File lib/sycamore/nothing.rb, line 77
def inspect
  '#<Sycamore::Nothing>'
end
like?(object) click to toggle source

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
nothing?() click to toggle source

(see Tree#nothing?)

# File lib/sycamore/nothing.rb, line 28
def nothing?
  true
end
to_native_object(sleaf_child_as: nil, **args) click to toggle source
# File lib/sycamore/nothing.rb, line 59
def to_native_object(sleaf_child_as: nil, **args)
  sleaf_child_as
end
to_s() click to toggle source

A string representation of the Nothing tree.

@return [String]

# File lib/sycamore/nothing.rb, line 68
def to_s
  'Tree[Nothing]'
end