开发者

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

开发者 https://www.devze.com 2022-12-23 11:54 出处:网络
I\'m trying to write a new entry to a rails database.yml and for some reason I\'m getting quotes around this entry

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

精彩评论

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