Last active
December 11, 2015 07:09
-
-
Save xslim/4564504 to your computer and use it in GitHub Desktop.
Playing with selecting and sorting of Hash
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
class Hash | |
def select_and_sort_by(whitelist) | |
whitelist.inject({}) do |h,k| | |
k = k.to_sym if k.is_a? String | |
h[k] = self[k] if self.has_key? k | |
h | |
end | |
end | |
end | |
# collection.select_and_sort_by({:key1, :key3}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment