Ruby Koans part 2 - my thoughts thus far

July 2, 2014

I recently discovered how awesome the Ruby Koans are. The last 2 days I have gone through:

###Part 2

  1. about_keyword_arguments
  2. about_constants
  3. about_control_statements
  4. about_true_and_false
  5. about_triangle_project

###Part 3

  1. about_exceptions
  2. about_triangle_project_2
  3. about_iteration
  4. about_blocks
  5. about_sandwich_code
  6. 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

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,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.

Discussion, links, and tweets

My name is Deon Heyns and I am a developer learning things and documenting them in realtime. Python, Ruby, Scala, .NET, and Groovy are all languages I have written code in. I appeared in the New York Post once. I host my code up at GitHub and Bitbucket so have a look at my code, fork it and send those pull requests.

comments powered by Disqus