Ruby Tricks and Oddities
Just looked through Julio Santos’ “Ruby Things” on Speaker Deck and learned some quirkly little things about Ruby.
Creating hashes from arrays. 2 different outcomes:
1 2 3 4 5 6 7 8 | |
The zip method “converts any arguments to arrays, then merges elements of self with corresponding elements from each argument.” For example:
1 2 3 4 | |
Santos demonstrates that you can use zip to create hashes:
1 2 3 4 5 6 | |
And yesterday while wishing a collect_with_index method existed, my group discovered that you can combine each_with_index with collect!
1 2 3 4 5 6 7 8 9 10 11 | |