Class: Psych::Visitors::YAMLTree::Registrar

Inherits:
Object
  • Object
show all
Defined in:
lib/psych/visitors/yaml_tree.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeRegistrar

Returns a new instance of Registrar.



17
18
19
20
21
# File 'lib/psych/visitors/yaml_tree.rb', line 17

def initialize
  @obj_to_id   = {}.compare_by_identity
  @obj_to_node = {}.compare_by_identity
  @counter     = 0
end

Instance Method Details

#id_for(target) ⇒ Object



31
32
33
# File 'lib/psych/visitors/yaml_tree.rb', line 31

def id_for target
  @obj_to_id[target] ||= (@counter += 1)
end

#key?(target) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/psych/visitors/yaml_tree.rb', line 27

def key? target
  @obj_to_node.key? target
end

#node_for(target) ⇒ Object



35
36
37
# File 'lib/psych/visitors/yaml_tree.rb', line 35

def node_for target
  @obj_to_node[target]
end

#register(target, node) ⇒ Object



23
24
25
# File 'lib/psych/visitors/yaml_tree.rb', line 23

def register target, node
  @obj_to_node[target] = node
end