开发者

Why does yaml.dump add quotes this key-value pair

I'm trying to write a new entry to a rails database.yml and for some reason I'm getting quotes around this entry

db_yml开发者_Go百科 => {'new_env' => {'database' => 'database_name', '<<' => '*defaults' }} File.open("#{RAILS_ROOT}/config/database.yml", "a") {|f| YAML.dump(db_yml, f)}

returns

---
 new_env: 
   database: database_name
   "<<": "*defaults"

I don't know why the "---" and the quotes around the defaults are returned, any thoughts on how to prevent?

thanks!


<< and * have special meaning in YAML. Quotes are used to show that << is not merge and * is not an alias.


the --- is just to mark the start of YAML dump.

The double quote around << it's because can be interpretate in YAML format. So it's escape.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜