Created
October 17, 2011 18:46
-
-
Save freeformz/1293428 to your computer and use it in GitHub Desktop.
merge defaults, preserving existing entries .. Is there a better way?
This file contains 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
class Hash | |
def with_defaults(defaults={}) | |
self.merge(defaults) { |k,o,n| o } | |
end | |
def with_defaults!(defaults={}) | |
self.merge!(defaults) { |k,o,n| o } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case:
And I hate doing it the other way. feels wrong.
and #new is klunky and doesn't actually do what I want
Am I missing something?