Skip to content

Instantly share code, notes, and snippets.

@forforf
Created March 17, 2011 19:03
Show Gist options
  • Save forforf/874919 to your computer and use it in GitHub Desktop.
Save forforf/874919 to your computer and use it in GitHub Desktop.
Add to a hash whether the hash exists or not
def create_hash(akey, avalue, ahash)
ahash ||= {}
ahash.merge!({akey => avalue}) if akey
ahash
end
p create_hash(:a, 'A', {:z => ['z', 'Z']})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment