How to Dynamically Create Instance Variables in Ruby This post shows one way to dynamically initialize multiple instance variables in a Ruby class using metaprogramming. If you need to pass multiple, separate pieces of data to a constructor (and cannot refactor the code for some reason), it's a pretty good technique to reduce all the repetitive code.
How to Render SVG Icons in Ruby on Rails This post shows how I render SVG icons in my Ruby on Rails applications. Instead of littering your HTML with complicated SVG tags, keep them tucked away in a folder as an ERB partial, and use a Rails helper to insert it in your views. Result: reusable, customizable icons and readable HTML.
How to Implement Rails-like Dynamic Views in Ruby In this article, we will learn 'one' way to implement the controller-to-view data handoff using instance variables, just like Rails, and following the same conventions as Rails. Although it's a highly simplified implementation to keep things simple, I hope you'll find it fun and learn something new. This article is for Members only
Implementing Rails-like Controllers in a No-Rails App In its essence, a controller class in Rails is a coordinator. It accepts the incoming HTTP request and builds the data required by the view using the domain models. This post shows a highly simplified implementation of the controller pattern for a better understanding of Rails controllers. This article is for Members only
Understanding the Concept of Binding in Ruby Binding is an elegant way to access the current scope (variables, methods, and self) in Ruby. Typically, you use it for building view templates and executing strings of Ruby code. The Ruby REPL also makes abundant use of binding. In this post, we'll learn what binding is and how it works.
Serving Static Files in Ruby This is the fourth article in the series where we build a simple, yet complete web app in plain Ruby, without using Rails to better understand how Rails works. In this article, we'll learn how to serve static files in plain Ruby, without using Rails. This article is for Members only
How to Split a List into N Equal Parts in Ruby (and Rails) This article shows you can split (or chunk) a list of items into n-equally sized parts using the `each_slice` method in Ruby and `in_groups_of` method in Rails.
Blocks, Procs, and Lambdas: A Beginner's Guide to Closures and Anonymous Functions in Ruby Closures and anonymous functions are very useful concepts, especially in functional programming. Ruby makes working with them a pleasure via its flavors like blocks, procs, and lambdas. This post provides an in-depth tutorial and shows the subtle differences between them.
How Module Autoloading Works in Ruby and Rails Autoloading allows you to speed up the initialization of your library by lazily loading the code only when you need it. This post explains how the autoload method works in Ruby and how Rails overrides this method to provide its own implementation that follows the Rails naming conventions.
Practical Stimulus: How to Toggle CSS Classes This second article in the 'Stimulus in Practice' series shows how you can work with HTML classes using Stimulus. Specifically, we'll learn how to toggle classes on an element. This is useful when you want to show or hide certain elements or update the design in response to user interaction.
Practical Stimulus: Capture User Input Stimulus is a JavaScript library that works really well with the HTML-over-the-wire approach of building web applications. In this series of articles, we'll learn how to accomplish common front-end tasks using Stimulus. This post shows how to capture user input and display it on the screen.
Unix: A History and a Memoir I recently read Brian Kernighan’s Unix: A History and a Memoir. If his name sounds familiar, Brian is also the author of The C