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.
16 17 18 19 20 21 |
# File 'lib/psych/visitors/yaml_tree.rb', line 16 def initialize @obj_to_id = {} @obj_to_node = {} @targets = [] @counter = 0 end |
Instance Method Details
#id_for(target) ⇒ Object
34 35 36 |
# File 'lib/psych/visitors/yaml_tree.rb', line 34 def id_for target @obj_to_id[target.object_id] ||= (@counter += 1) end |
#key?(target) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/psych/visitors/yaml_tree.rb', line 28 def key? target @obj_to_node.key? target.object_id rescue NoMethodError false end |
#node_for(target) ⇒ Object
38 39 40 |
# File 'lib/psych/visitors/yaml_tree.rb', line 38 def node_for target @obj_to_node[target.object_id] end |
#register(target, node) ⇒ Object
23 24 25 26 |
# File 'lib/psych/visitors/yaml_tree.rb', line 23 def register target, node @targets << target @obj_to_node[target.object_id] = node end |