The Ruby Way - What does it mean?
Two blocks of code, which would you prefer?
The Ruby Way?:
The first block is my first attempt at the about_triangle_project_2 from the Ruby Koans pretty much the sort of code you would expect to see from the first attempt when learning a new language properly. The second block is something I found after I googled for other solutions. I prefer the second solution over mine since it is much clearer at conveying what is happening. The intent is much easier to grasp than my attempt and its less code.
So what or how do you explain the Ruby Way and how do you start thinking in the Ruby Way? Those are questions I don’t have an answer to…yet! Hal Fulton said
On the one hand, it means a method or technique, but it can also mean a road or path. Obviously these two meanings are interrelated, and I think when I say, “the Ruby Way,” I mean both of them.
So to me the interesting point is “the method or technique”. I looked for some more examples today and came across this code that swaps two values
Really!?!? Is that’s all it takes to swap values.
Look at this
compared to this
I know that I would prefer the first code block over the second. Also, while searching I came across the GitHub Style Guide for Ruby, that has some nice advice on coding style that I will often be revisiting.
I am still figuring out the how. To me I don’t believe that thinking or writing code in the Ruby Way will happen overnight. I have read a few suggestions of blogs and books that will help you to start doing things in the Ruby Way but clearly this is a skill that needs to be practiced to master. All I can say is that this language is very impressive and around every corner has more and more sweet features