SHARE
TWEET

Untitled

a guest Feb 26th, 2012 19 Never
  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
RAW Paste Data
Top