The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
YAML's Merge Key

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
YAML's Merge Key Posted: Jul 26, 2005 10:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: YAML's Merge Key
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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?

Read: YAML's Merge Key

Topic: RubyistMagazineVol8 Previous Topic   Next Topic Topic: Only publishers care about the last 20%

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use