Created
December 14, 2011 10:09
-
-
Save madsheep/1475988 to your computer and use it in GitHub Desktop.
keep on trying
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 keep_on_trying(*args) | |
args.inject(self.dup){|memo, e| memo.dup.delete(e) if memo.is_a?(Hash) } | |
end | |
end | |
ruby-1.9.2-head :109 > a | |
=> {:test=>{:this=>"aaa"}} | |
ruby-1.9.2-head :110 > a.keep_on_trying(:test) | |
=> {:this=>"aaa"} | |
ruby-1.9.2-head :111 > a.keep_on_trying(:test, :this) | |
=> "aaa" | |
ruby-1.9.2-head :112 > a.keep_on_trying(:test, :this, :plz) | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment