Class: Sycamore::NothingTree

Inherits:
Tree
  • Object
show all
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:

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

#data

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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

#freezeObject



80
81
82
# File 'lib/sycamore/nothing.rb', line 80

def freeze
  super
end

#inspectString

A developer-friendly string representation of the Nothing tree.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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_sString

A string representation of the Nothing tree.

Returns:

  • (String)


67
68
69
# File 'lib/sycamore/nothing.rb', line 67

def to_s
  "Tree[Nothing]"
end