Hello, world! Here we are at the end of yet another Phase. This time we dove into the wild world of back-end programming by learning the language that strives to be both functional and beautiful. Yes, I’m talking about Yukihiro Matsumoto’s Ruby.
Ruby strives to be simple and effective. “Matz,” the affectionate nickname for lead developer Matsumoto, aimed for the principle of least surprise. What you put in and what returns should never be too unexpected. This was a deviation from his experience as a C++ programmer before opting to create the new language of Ruby in the mid-1990s.
The key feature of Ruby is its fundamental object orientation. Every single value is an object. Every function written is a method that can be applied to these objects. These objects are divided between classes and instances, and methods can thus be divided themselves between class methods or instance methods to achieve the desired output from your code. For example, a class would be something like cars and an instance would be something like a Toyota Tacoma.
Class methods work to create new instances within that class. Instance methods work to return the result of an instance of its Class run through a function (method). Imagine the specific Class “BasicArithmetic,” which would have instance methods of sum, subtract, divide, multiply, etc. Class methods would search the whole database of instances (numbers), but the instance methods would be the ones conducting the actual mathematical operations by utilizing one or more instances of the Class “BasicArithmetic.”
Much like React supercharges JavaScript, Ruby’s database management is enhanced by incredible “gems,” the term for aggregated code libraries that enhance and streamline the capabilities of vanilla Ruby. Two of the most important are Active Record and Sinatra.
Active Record aids in the retention of data in the database and in creating relations between databases. ORM, Object Relational Mapping, connects the objects created by Ruby utilizing the language of Ruby instead of direct SQL statements. It allows the programmer to utilize a new set of tools to create tables, populate them with data and link them.
Sinatra, then, takes this a step further by allowing programmers to very easily ship web apps with minimal requirements. The strongest aspect, in my opinion, is the ease with which one can connect to external APIs to draw data into your tables created by Active Record. This data can then be stored and shipped to the front end and, ultimately, manipulated by whatever front-end language is preferred to create a fully-functional web app.
All in all, working with Ruby was very enjoyable, and Sinatra and Active Record made it incredibly easy to perform complex tasks. Our next stop is putting Ruby on Rails, which implements a full-stack framework. See you in three weeks!