class Psych::Visitors::ToRuby

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.

Public Instance Methods

revive_hash(hash, o) click to toggle source

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

# 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