stupid hash experiments in ruby


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. foo = {"a" => {"aa" => "b"}, "b" => {"ab" => "c"}, "c" => {"ac" => "d"}}
  2. #=> {"a"=>{"aa"=>"b"}, "b"=>{"ab"=>"c"}, "c"=>{"ac"=>"d"}}
  3.  
  4. foo.keys
  5. #=> ["a", "b", "c"]
  6.  
  7. foo.values(&:keys)
  8. foo.values(&:keys).each(&:values)
  9. foo.values(&:keys).each(&:values).each(&:keys)
  10. foo.values(&:values).each(&:keys)
  11. foo.values(&:values).each(&:values)
  12. #=> [{"aa"=>"b"}, {"ab"=>"c"}, {"ac"=>"d"}]
  13.  
  14. foo.values(&:keys).collect(&:values)
  15. foo.values(&:values).collect(&:values)
  16. foo.values(&:values).each(&:keys).collect(&:values)
  17. foo.values(&:keys).each(&:keys).collect(&:values)
  18. foo.values(&:keys).each(&:values).collect(&:values)
  19. #=> [["b"], ["c"], ["d"]]
  20.  
  21. foo.values(&:keys).collect(&:keys)
  22. foo.values(&:values).collect(&:keys)
  23. foo.values(&:values).map(&:keys)
  24. foo.values(&:keys).each(&:values).collect(&:keys)
  25. #=> [["aa"], ["ab"], ["ac"]]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.