Created
December 23, 2009 19:17
-
-
Save r38y/262723 to your computer and use it in GitHub Desktop.
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
require 'yaml' | |
class Hash | |
def filter(*keys) | |
self.inject({}){|h,v| h[v.first] = v.last if keys.include?(v.first); h} | |
end | |
end | |
test_hash = {'one' => 1, 'two' => 2, 'three' => 3} | |
puts test_hash.to_yaml | |
puts test_hash.filter('one').to_yaml | |
puts test_hash.filter('one', 'two').to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment