Systems | Development | Analytics | API | Testing

How to Handle Exceptions in Ruby with Rescue

Ruby has a robust error handling mechanism called rescue. The way it works is the keyword rescue specifies an exception handler that will catch and handle any exceptions that are raised in the begin block, the code block preceding the rescue block that may cause an exception. Here’s how it looks: When an exception occurs in the begin code block, Ruby transfers control to the rescue block and executes the code within it.

Build Custom ActiveStorage Analyzers for Ruby on Rails

In this series, we will take a close look at the architecture of ActiveStorage for Rails. In this first part, we will examine how ActiveStorage treats uploaded data and how to extend this process. The second part will explore how to augment the presentation of uploaded assets. But first, let's quickly define what ActiveStorage does.

Cool Ruby regex tricks

In Ruby, regular expressions can be challenging to learn, but they're a powerful tool to parse and manipulate text in your Ruby code. There are plenty of gotchas, but Ruby regex skills will pay dividends if you take the time to practice them. We thought it'd be fun to complement our article about regex conditionals in Ruby by looking at some other neat but uncommon tricks you can do with regexes in Ruby. Some of these tricks are Ruby-specific, but many apply to regular expressions in any language.

Understanding the insertion sort algorithm in Ruby

As we explore different methodologies for sorting data, we turn to the insertion sort algorithm. There are a number of reasons to like insertion sort! First, insertion sort is stable, which means that it does not change the relative order of elements with equal keys. It's also an in-place algorithm, meaning that it does not create a new array to store the sorted elements. Finally, insertion sort is a pretty simple algorithm to implement, as you'll soon see!

Comparing Go vs Ruby

Ruby and Rails are great tools that allow you to create complex web applications quickly. Well, some kinds of complex web applications. While they excel at traditional, monolithic, server-rendered applications, they fail to excel at delivering real-time or distributed services. This is why it's so handy for Rubyists to learn a programming language like Go. Go is designed to write lightweight services that handle lots of inbound connections.

What's new in Ruby 3.4

According to Ruby tradition, the core team will release Ruby 3.4 on December 25—but the preview has been out since May! If you're anticipating the release like we are, you're probably wondering what's new in Ruby 3.4. There aren't any huge changes in this release, but you'll want to be aware of a few really cool things. Let's dig into some of the language changes first.

Server-sent Events and WebSockets in Rack for Ruby

In the previous part of this series, we discovered how to create persistent connections in Rack in theory, but now we'll put what we learned into practice. The web has two formalized specifications for communication over a persistent connection: server-sent events (SSEs) and WebSockets. WebSockets are widely used and highly popular, but SSEs are far less well-known. Let's explore them first.