Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.27 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # destructures the parameter values according to the order of the sorted keys
  2. # Usage:
  3. # hash = { :macbook => 1, :iphone => 2, :ipad => 3 }
  4. # ipad, iphone, macbook = destructuring_bind(hash)
  5. def destructuring_bind(hash)
  6.   hash.sort_by {|k, v| k.to_s }.map {|e| e[1] }.flatten
  7. end
clone this paste RAW Paste Data