YAML's Merge Key #
Some of you might find YAML’s merge key convenient, especially in your database.yml
files within Rails. The merge key basically mixes two hashes together, just like the Hash#merge
method. You just place a <<
key in a hash with a value which is a hash or an array of hashes.
death masks are?: sad: 2 <<: {magnificent: 4}
Is just like:
death masks are?: sad: 2 magnificent: 4
So, if you are using the same login for different databases (which is likely very common):
login: &login adapter: mysql host: localhost username: portly password: 666HELL666 development: database: rails_dev <<: *login test: database: rails_test <<: *login production: database: rails_prod <<: *login
The login
anchor is set up first and then its anchor is used throughout. I don’t think having a login
entry in the file does any harm, does it?
MenTaLguY
My, that is handy.
Is there an equivalent of that for string interpolation?
_why
Well, there’s yip.
jvoorhis
Very clever indeed. Is there any way to make it span files?
MenTaLguY
I love Ruby. Seriously.
<MenTaLguY> Is there a #{thingy} for #{stuff I want to do}?
<Ruby master> Well, there’s #{rubyforge project}.
Cai
There was just a checkin to the Rails tree to allow ERb in the database.yml file.
ceejayoz
666HELL666? Hee!
bruce
It’s neat to see yip mentioned after so long a time.
Please note that yip is available as a rubygem. You can reach me at wbruce (gmail) if you any problems.
procreate
Just make sure you use quotes when you use slashes like so:
socket: ”/tmp/mysql.sock”
Comments are closed for this entry.