Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johanlunds/01a3cf67c53d6aa374a0d255381cd035 to your computer and use it in GitHub Desktop.
Save johanlunds/01a3cf67c53d6aa374a0d255381cd035 to your computer and use it in GitHub Desktop.
# A utility class with added behavior that it raises an exception if a key does not
# exist in hash.
module HashWithExceptionOnMissingKey
def self.new(hash)
obj = Hash.new do |hash, key|
raise ArgumentError, "Key #{key.inspect} does not exist in hash"
end
obj.merge!(hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment