0
我有兩個我已經序列化的YAML文件。Ruby:添加哈希/合併YAML對象
「PP」 來自
ἀγαπάω:
present: ἀγαπάω
future: ἀγαπήσω
aorist: ἠγάπησα
...更多...
「詞素」 來自
ἀγαπάω:
pos: V
bdag-headword: ἀγαπάω
strongs: 25
gloss: I love
...many more...
我試圖添加值「光澤「和」強「到」pp「,否則將pp值與這些來自詞位的新值合併。顯然ruby不允許插入新值,同時迭代散列。到目前爲止,我有:
pps = Hash.new
pp.each do |p|
lexemes.each do |lex, arr|
if lex.match /^#{p[0]}$/
#match found
puts "p #{p[0]} ... lex #{lex}...#{arr['strongs']}....#{arr['gloss']} .
(pps[p[0]] ||= []) << p
pps[p[0]].push(:strongs => arr['strongs'], :gloss => arr['gloss'])
end
end
end
其傾倒收益時:
"ἀγαπάω":
- - "ἀγαπάω"
- present: "ἀγαπάω"
future: "ἀγαπήσω"
aorist: "ἠγάπησα"
- :strongs: 25
:gloss: I love
當我真的想:
ἀγαπάω:
present: ἀγαπάω
future: ἀγαπήσω
aorist: ἠγάπησα
strongs: 25
gloss: I love
任何想法,/我應該如何管理新數據的插入?
謝謝!