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.
精彩评论