Skip to content

Instantly share code, notes, and snippets.

@simonoff
Forked from xslim/hash.rb
Last active December 11, 2015 07:09
Show Gist options
  • Select an option

  • Save simonoff/4564560 to your computer and use it in GitHub Desktop.

Select an option

Save simonoff/4564560 to your computer and use it in GitHub Desktop.
class Hash
def select_and_sort_by(whitelist)
whitelist.inject({}) do |m,k|
k = k.to_sym
m[k] = self[k] if self.has_key?(k)
m
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