I was writing a rake task to handle importing data from an older community system and needed to set a default value for anything that the old system didn’t have. I was using hashs and thought to myself “It would be sweet if hashs had defaults.” After a quick doc check I found out that hashs do infact support defaults. I encourage you to check out the Ruby Docs http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-default

Continue reading

Author's picture

Brian Pearce

Software Engineer, Endurance Cyclist,
Rubiest, and Rustacean

Software Engineer

Barcelona, Spain