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.



114
115
116
# File 'lib/sycamore/nothing.rb', line 114

def !
  true
end

#==(other) ⇒ Boolean

Checks if the given object is an empty tree.

Returns:

  • (Boolean)


94
95
96
# File 'lib/sycamore/nothing.rb', line 94

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)


35
36
37
# File 'lib/sycamore/nothing.rb', line 35

def absent?
  true
end

#child_of(node) ⇒ Object



55
56
57
# File 'lib/sycamore/nothing.rb', line 55

def child_of(node)
  self
end

#freezeObject



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

def freeze
  super
end

#inspectString

A developer-friendly string representation of the Nothing tree.

Returns:

  • (String)


77
78
79
# File 'lib/sycamore/nothing.rb', line 77

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)


132
133
134
# File 'lib/sycamore/nothing.rb', line 132

def like?(object)
  object.nil? or object.equal? self
end

#nothing?Boolean

Checks if this is the Sycamore::Nothing tree.

Returns:

  • (Boolean)


28
29
30
# File 'lib/sycamore/nothing.rb', line 28

def nothing?
  true
end

#to_native_object(sleaf_child_as: nil, **args) ⇒ Object



59
60
61
# File 'lib/sycamore/nothing.rb', line 59

def to_native_object(sleaf_child_as: nil, **args)
  sleaf_child_as
end

#to_sString

A string representation of the Nothing tree.

Returns:

  • (String)


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

def to_s
  'Tree[Nothing]'
end