views:

90

answers:

2

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 => {'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!

A: 

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.

shingara
so what if I wanted to write to the file but not have quotes there and not have the lines that mark the start of the dump? Is there a way to do that?
jason gagne
You can't if you want use some reseved character
shingara
+1  A: 

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