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



12
13
14
15
16
# File 'lib/psych/visitors/yaml_tree.rb', line 12

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

Instance Method Details

#id_for(target) ⇒ Object



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

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

#key?(target) ⇒ Boolean

Returns:

  • (Boolean)


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

def key? target
  @obj_to_node.key? target.object_id
end

#node_for(target) ⇒ Object



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

def node_for target
  @obj_to_node[target.object_id]
end

#register(target, node) ⇒ Object



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

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