Class: Psych::Visitors::YAMLTree::Registrar
- Defined in:
- lib/psych/visitors/yaml_tree.rb
Overview
:nodoc:
Instance Method Summary collapse
- #id_for(target) ⇒ Object
-
#initialize ⇒ Registrar
constructor
A new instance of Registrar.
- #key?(target) ⇒ Boolean
- #node_for(target) ⇒ Object
- #register(target, node) ⇒ Object
Constructor Details
#initialize ⇒ Registrar
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
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 |