Understanding the Ruby Mindset and Culture
Ruby has had quite a history since its inception by Yukihiro Matsumoto. The adoption of the language by the community has, of course, influenced the direction in which Ruby has been focused. But, at its core, Ruby has been very straightforward in the way you can and the way you should write programs/scripts with it. Every language has its own peculiarities, which the community takes to define what a good practice is and what is considered “bad” code. While this may be entirely subjective, this subjectiveness paves the way for what the author’s original intention for creating the language was into what the community wants the language to become.
Ruby was created with the idea of being extremely easy to read, flexible, and object-oriented. The same can be said about the technologies that came to pass because of Ruby. I’m talking about frameworks created in Ruby, such as Ruby on Rails (https://rubyonrails.org) and Sinatra (http://sinatrarb.com/). But I’m also talking about other tools that were created with that same mindset, such as Chef (https://www.chef.io/). All of these tools have common traits but the trait that stands out the most is readability. Once you’re in the Ruby “realm,” you’re able to read and understand code made for vanilla Ruby, a Ruby on Rails application API, or even a Chef recipe to manage and configure infrastructure. Ruby does not automatically make your code more understandable or readable, but it goes a long way to give you the tools to make your code easier to read. Making your code understandable is key to focusing more on the business (or hobby) at hand and focusing less on trying to understand what some code is doing.
But before we get there, we will need to make the switch to the Ruby mindset. In this chapter, we will start our journey into this mindset by covering the following topics:
- Creating readable Ruby code
- Object-oriented Ruby
- Writing Ruby-esque code
You made up your mind to learn a new programming language. Congratulations! I, for one, would like to applaud this decision and hope it took you less time than it took me to be seriously curious about another programming language. I was a bit stubborn and reluctant at first, seeing every single downside of Ruby. My favorite phrase was, “I can do that in PHP easier.” But then, one day, it simply clicked and I never went back. Ruby has been my go-to language for a long time now. And I won´t try to oversell this to you. I refuse to say that Ruby is the best programming language there is because that would be answering a loaded question. There is no programming language that is universally better than the rest. What I can do is try to show you why I love Ruby.