Skip to content

Instantly share code, notes, and snippets.

@madsheep
Created December 14, 2011 10:09
Show Gist options
  • Save madsheep/1475988 to your computer and use it in GitHub Desktop.
Save madsheep/1475988 to your computer and use it in GitHub Desktop.
keep on trying
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