I am using Ruby on Rails 3.0.10 and I would like to build an hash key\\value pairs in a conditional way. That is, I would like to add a key and its related value if a condition
In case you want to add few keys under single condition, you can use merge:
merge
hash = { :key1 => value1, :key2 => value2, :key3 => value3 } if condition hash.merge!( :key5 => value4, :key5 => value5, :key6 => value6 ) end hash