I'm making dynamic yaml file
in Ruby
I have following hash
{
"defaults"=>
{"foo"=>"bar", "zip"=>"button"},
"node"=>
{
"<<"=>
{"foo"=>"bar", "zip"=>"button"},
"foo"=>"other"
}
}
when i try to parse it using
tree = Psych.parse your_data
data = ToRubyNoMerge.new.accept tree
having parser functions override like here
require 'psych'
class ToRubyNoMerge < Psych::Visitors::ToRuby
def revive_hash hash, o
if o.anchor
@st[o.anchor] = hash
hash.instance_variable_set "@_yaml_anchor_name", o.anchor
end
o.children.each_slice(2) { |k,v|
key = accept(k)
hash[key] = accept(v)
}
hash
end
end
class MyEmitter < Psych::Visitors::Emitter
def visit_Psych_Nodes_Mapping o
o.anchor = 'defaults' if o.anchor
super
end
def visit_Psych_Nodes_Alias o
o.anchor = 'defaults' if o.anchor
super
end
end
Now when i try
tree = Psych.dump yaml_constants
data = ToRubyNoMerge.new.accept tree
File.open(file, 'w') { |f| YAML.dump(data.to_yaml, f) }
It give me below error
psych/visitors/to_ruby.rb:23:in `initialize': wrong number of arguments (given 0, expected 2) (ArgumentError)
we can see that it makes sense , because revive_hash
is taking two arguments but the same thing worked for This guys . can anyone tell me what i'm doing wrong
Note: I'm following This Post for parsing and asked @matt for this issue but he's not responsing