Created
May 5, 2017 14:17
-
-
Save johanlunds/01a3cf67c53d6aa374a0d255381cd035 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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