Ruby Koans part 2 - my thoughts thus far
I recently discovered how awesome the Ruby Koans are. The last 2 days I have gone through:
###Part 2
- about_keyword_arguments
- about_constants
- about_control_statements
- about_true_and_false
- about_triangle_project
###Part 3
- about_exceptions
- about_triangle_project_2
- about_iteration
- about_blocks
- about_sandwich_code
- about_scoring_project
I have already mentioned how much I like Ruby thus far, and these past few Koans have just opened up my eyes to how easy and expressive Ruby is whilst still not requiring lines and lines of code.
The about_blocks section was especially interesting to me the lambda declaration was pretty neat
1
silence = lambda { |n| n + 1 }
The syntax for the find_all, map, collect and select are very succinct, and I certainly can see why many people new to programming pick Ruby because its so easy to read and grok. Just check this
1
2
3
[1,2,3,4,5,6].select { |item| (item % 2) == 0}
[1,2,3,4,5,6].collect { |item| (item % 2) == 0}
[1,2,3,4,5,6].find_all { |item| (item % 2) == 0}
See you can almost read that like any sentence and understand what is happening. I also touched on the Enumerable#inject method, but I still don’t fully understand why many people rave about it. It might just be a case of I don’t grok it yet. So my mission for the rest of the day is to try and understand it better and figure out why many a Rubist loves this method.
I will report back my findings tomorrow, and hopefully I will be able to impart my knowledge (or lack thereof) on the Enumerable#inject method.