Class: Psych::Visitors::ToRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/strut/extensions.rb

Overview

The next step is to convert the AST to a Ruby object. Psych does this using the visitor pattern with the ToRuby visitor. Here we patch ToRuby rather than inherit from it as it makes the last step a little easier.

Instance Method Summary collapse

Instance Method Details

#revive_hash(hash, o) ⇒ Object

This is the method for creating hashes. There may be problems with Yaml mappings that have tags.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/strut/extensions.rb', line 65

def revive_hash hash, o
  o.children.each_slice(2) { |k,v|
    key = accept(k)
    val = accept(v)

    val = { "value" => val, "line" => v.line} # line is 0 based, so + 1

    # Code dealing with << (for merging hashes) omitted.
    # If you need this you will probably need to copy it
    # in here. See the method:
    # https://github.com/tenderlove/psych/blob/v2.0.13/lib/psych/visitors/to_ruby.rb#L333-L365

    hash[key] = val
  }
  hash
end