Skip to content

Instantly share code, notes, and snippets.

@nickyp
Created October 21, 2010 10:17
Show Gist options
  • Save nickyp/638254 to your computer and use it in GitHub Desktop.
Save nickyp/638254 to your computer and use it in GitHub Desktop.
# destructures the parameter values according to the order of the sorted keys
# Usage:
# hash = { :macbook => 1, :iphone => 2, :ipad => 3 }
# ipad, iphone, macbook = destructuring_bind(hash)
def destructuring_bind(hash)
hash.sort_by {|k, v| k.to_s }.map {|e| e[1] }.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment