Sign up for my newsletter
Let's learn to become better developers.
Metaprogramming in Ruby
Metaprogramming in Ruby enables you to produce elegant, clean, and beautiful programs as well as unreadable, complex code that’s not maintainable. This book teaches you the powerful metaprogramming concepts in Ruby, and how to use them judiciously.
September 12, 2022
How to Get an Object's Class Name in Rails
This post explores a few different ways in which you can get an object's class name in both Ruby and Rails.
September 11, 2022
A Deep Dive Into Database Migrations in Rails
Like source code, database schema changes and evolves over time. Migrations are a feature of Active Record that allows you to manage the database schema changes gracefully, without writing any SQL. This post contains my notes on Active Record migrations from the official Rails guides.
September 09, 2022
Attributes API in Rails
Sometimes, you want to set default values on your ActiveRecord objects and convert them to a different type. Rails provides a handy attribute method that lets us do that, and much more. In this post, we will try to understand how to use the attributes API to achieve this.
September 08, 2022
How to Get the Current Absolute URL in Rails
Every Rails controller includes two accessor methods pointing to the request and the response objects associated with the current HTTP request cycle. The request method returns an instance of the ActionDispatch::Request class, which wraps the HTTP request and provides a nice API to inspect the request.
September 07, 2022
How to Rename a Database Column in Rails
Solution 1: Undo Last MigrationIf it is a simple typo in the last migration, use the db:rollback command to undo the last change. Then open the previous migration file, fix your typo, and rerun the migration. Make sure that no new data is inserted in the table or that no one on your team runs the stale migration.
September 06, 2022
Metal Controller in Rails
The ActionController::Base class is the great-grandfather of all Rails controllers, but doesn't get much attention. In this post, we will examine this Metal class and how it works. We'll also trace the path of an incoming HTTP request to Rails controllers.
August 16, 2022
Active Job: How does it work?
In this article, I explain the journey of a background job, from its creation to execution. We will learn how it’s configured and enqueued, and how an adapter invokes it. We will also see the different ways to configure a job.
August 12, 2022
Up and Running with Minitest
I love minitest. Minitest is simple. There’re a few ways to write tests, and they are so intuitive. I learned it last year, when I got into Ruby, and since then I haven’t really felt the need to dive into the docs that frequently. It just works.
June 29, 2022
Ruby Shortcut to Call a Method with Each Array Item as Parameter
As a Ruby programmer, you probably know the &: shortcut to call a method on each item in an array. For example, this snippet will call the to_s method on :foo and :bar.
June 10, 2022