views:

247

answers:

3

Hello,

I have the following hash table:

  COUNTRIES = {
  'France' => 'FR', 
  'German' => 'GE', 
  'United Kingdom' => 'UK'
  }

I have it in my model and use it in my views so the countries are displayed as a select box. Now I have one view where I want all those values plus one more value "Europe" => 'EU' to be shown. Meaning I would have:

  COUNTRIES = {
  'Europe' => 'EU', 
  'France' => 'FR', 
  'German' => 'GE', 
  'United Kingdom' => 'UK'
  }

Now I can create a new hash table but I dont want to repeat the same values in a new table.

So, how can I re-use the same table, adding one more value just for a particular view?

All ideas are welcome.

+4  A: 
customCountries = COUNTRIES.clone
customCountries['Europe'] = 'EU'
Aurril
Thank you @Aurril
Adnan
As far as I know it's Hash.new(default_value) and that is most probably not what you wanted.
Jonas Elfström
You are right, edited my original post.
Aurril
Smoother one-liner below by Jonas Elfström
berlin.ab
No need to downvote me. My solution is completly legit.
Aurril
A: 
"Europe".to_country!
Beerlington
+2  A: 

Try this

custom = {'Europe' => 'EU'}.merge(COUNTRIES)
Jonas Elfström