I've stopped using code coverage tools a number of years ago as the effort to maintain a test suite with 100% code coverage was quite significant, but nowadays the coverage report can be a useful tool when working with LLMs. Unfortunately, the recommended SimpleCov setup for Ruby on Rails does not work because Rails now uses a parallel test runners and SimpleCov needs to be setup accordingly,…
I've noticed that many Ruby developers tend to suffer from "classitis," as coined by John Ousterhout in his "A Philosophy of Software Design," where there is an explosion of shallow modules (or, in our case, classes) instead of having fewer deep modules. I understand the general criticism that ActionController instances aren't really objects, but sure this can't be the best alternative : module…
One of the things I really enjoy about Ruby on Rails is that it has a lot of tiny conveniences that can speed up your workflow a lot. For example, I recently needed to quickly convert Markdown to HTML, but I wasn't sure which gem to use: a quick search revealed the venerable Redcarpet , which is mostly written in C, but also Commonmarker , which wraps a Rust library and provides some additional…
I've found that the best way to set up Posgres for local development is via Docker, since it has some clear benefits over using system packages on Windows (via WSL2) or Linux. There are three steps to configure Postgres for your Rails application: Install the Postgres server Install Postgres libraries for development Configure your application to connect to the Postgres container Installing the…
I've recently seen a code sample about working with Stripe webhooks in Rails applications and I've noticed the following code in the controller: class StripeController < ApplicationController skip_before_action :verify_authenticity_token , only : [ :webhook ] def webhook # Sample code for handling Stripe webhook events end end First of all, I want to point out that creating good code examples is…
Instance variables (or instance attributes) in Ruby are prefixed with an @ sign: class Person def initialize ( salutation : nil , first_name : , last_name : ) @salutation = salutation @first_name = first_name @last_name = last_name end def name [ @salutation , @first_name , @last_name ] . compact . join ( ' ' ) end end john = Person . new first_name : 'John' , last_name : 'Doe' john . name # =>…