Skip to content

Instantly share code, notes, and snippets.

@xslim
Last active December 11, 2015 07:09
Show Gist options
  • Save xslim/4564504 to your computer and use it in GitHub Desktop.
Save xslim/4564504 to your computer and use it in GitHub Desktop.
Playing with selecting and sorting of Hash
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