Book Image

From PHP to Ruby on Rails

By : Bernard Pineda
4 (1)
Book Image

From PHP to Ruby on Rails

4 (1)
By: Bernard Pineda

Overview of this book

Are you a PHP developer looking to take your first steps into the world of Ruby development? From PHP to Ruby on Rails will help you leverage your existing knowledge to gain expertise in Ruby on Rails. With a focus on bridging the gap between PHP and Ruby, this guide will help you develop the Ruby mindset, set up your local environment, grasp the syntax, master scripting, explore popular Ruby frameworks, and find out about libraries and gems. This book offers a unique take on Ruby from the perspective of a seasoned PHP developer who initially refused to learn other technologies, but never looked back after taking the leap. As such, it teaches with a language-agnostic approach that will help you feel at home in any programming language without learning everything from scratch. This approach will help you avoid common mistakes such as writing Ruby as if it were PHP and increase your understanding of the programming ecosystem as a whole. By the end of this book, you'll have gained a solid understanding of Ruby, its ecosystem, and how it compares to PHP, enabling you to build robust and scalable applications using Ruby on Rails.
Table of Contents (15 chapters)
1
Part 1:From PHP to Ruby Basics
8
Part 2:Ruby and the Web

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.