Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. my_hash = {a: 'qwe', b: 'zcx', c: 'dss', d: 'ccc', e: 'www' }
  2.  
  3. my_hash = {a: 'qwe', b: 'zcx', c: 'dss', d: 'ccc' }
  4.  
  5. my_hash = {a: 'qwe', b: 'zcx', c: 'dss', e: 'www' }
  6.  
  7. my_hash.to_a.combination(4).to_a.sample.to_h
  8. # => {:a=>"qwe", :b=>"zcx", :c=>"dss", :e=>"www"}
  9. my_hash.to_a.combination(4).to_a.sample.to_h
  10. # => {:a=>"qwe", :c=>"dss", :d=>"ccc", :e=>"www"}
  11.  
  12. my_hash.keys.combination(4).map { |keys| Hash[keys.map { |k| [k, my_hash[k]] }] }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement