Systems | Development | Analytics | API | Testing

Ruby

Unlocking the Power of Lambdas in Ruby

Lambdas are a powerful feature of the Ruby language. They allow you to wrap logic and data into a portable package. In this post, we’ll cover how and when to use lambdas. You'll also learn about the difference between lambdas and Procs, and the performance profile of lambda functions. The code examples have been tested with 2.6 and 2.7 and should work with most modern Rubys. Use the links below to skip ahead in the tutorial.

Diving into Custom Exceptions in Ruby

Customizing exceptions is usually not a common concern during software development. But if you catch an error in an observability tool and can't correctly and quickly identify the problem, you may need more information and details about an exception. This article will show you how to customize exceptions in Ruby and mitigate potential future problems due to a lack of error information. Let's dive straight in!

Authorization Gems in Ruby: Pundit and CanCanCan

Today, many web applications will feature pages that are publicly available — like a homepage — and more secure ones where a user has to log in to get access. The process of user registration, logging in, and tracking user session state is called "authentication". At the same time, when dealing with logged-in users, it's necessary to separate actions and resources that are available to them depending on their user roles. For example, "admins" generally have more access than normal users.

How to Handle ActiveRecord:: RecordNotFound in Ruby

ActiveRecord::RecordNotFound in Ruby is an error that occurs when an application is unable to find a record in the database that corresponds to the provided parameters. ActiveRecord is a Ruby gem that is used to interact with databases in a Rails application. It provides an object-relational mapping (ORM) layer that allows us to work with database records as if they were Ruby objects.

How to Fix Ruby Bundle Install Errors

A bundle install command in Ruby is used to install all of a project's dependencies. But occasionally, this command could falter and issue an error. Numerous variables might be to blame for this issue, and fixing it might prove challenging. In this post, we’ll go through some of the typical reasons for bundle install errors in Ruby along with solutions.

Calling Ruby Methods in C: Avoid Memory Leaks

Memory leaks are a pain for gem users. They are hard to track and can lead to expensive infrastructure costs. Memory leaks within a C extension are even worse. You'll see a lot of tools and articles about finding leaks in Ruby. However, you don't have the same access to internals in C. A naive usage of rb_funcall can cause memory leaks: it's much better to use rb_protect instead. So, if you are a C extension writer, please read on for the sake of developers who will use your gem. Let's get started!

Runtime Errors in Ruby

Exceptions are unintended events that take place when a program is being executed or during its runtime causing disruptions to the program's overall logic. In Ruby, a program is enclosed between the begin and end blocks and a rescue block is used to tell what types of exceptions are to be handled. When no class is specified, by default, a RuntimeError is raised by Kernel#raise.