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
Probably best to keep it simple if you're concerned about readability:
hash = {} hash[:key1] = value1 hash[:key2] = value2 if condition? hash[:key3] = value3 ...