Skip to content

Instantly share code, notes, and snippets.

@twe4ked
Last active October 11, 2016 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twe4ked/43587cc900f2aead7533823235bcc031 to your computer and use it in GitHub Desktop.
Save twe4ked/43587cc900f2aead7533823235bcc031 to your computer and use it in GitHub Desktop.
h = Hash.new { |hash, key| hash[key] = hash.fetch(key) { hash.values.max.to_i + 1 } }
# > h['foo']
# 1
# > h['foo']
# 1
# > h['bar']
# 2
require 'securerandom'
h = Hash.new { |hash, key| hash[key] = hash.fetch(key) { SecureRandom.uuid } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment