#536 — January 21, 2021

Read on the Web

💡 One of the most popular recurring features we've added to our sister Postgres Weekly newsletter has been a 'tip of the week.' We've been looking to begin this in Ruby Weekly too, and thanks to the hard work of Jemma Issroff we've got out first one this week. Don't miss it at the end of this issue :-)
__
Peter Cooper, editor

Ruby Weekly

How Fast is Ruby 3 on Rails? — The king of running Ruby and Rails benchmarks is back with a look at how Ruby 3 handles Rails from a performance point of view. Spoilers: The final release of Ruby 3.0 is more stable under load than preview1 and the overall performance is not dissimilar to that under 2.7.

Noah Gibbs

▶  DHH Talks Hotwire, Rails Next and the 'DHH Stack' — Whatever David Heinemeier Hansson (DHH) does is of natural interest to Rails developers and many Ruby developers too, so it’s nice to hear him chat at length on his current attitudes to things including Hotwire, ‘Rails 7’, and how he starts new projects.

Remote Ruby Podcast podcast

Free eBook: Efficient Search in Rails with Postgres — Speed up a search query from seconds to milliseconds and learn about exact matches, trigrams, ILIKE, and full-text search.

pganalyze sponsor

IRB’s New Built-In Time Measuring Command — Ruby 3.0 added measure, which you might know allows you to measure time, but did you know there’s a stackprof option? And, did you know you can add your own custom measures as well? (Jemma also contributed our first Tip of the Week which you can find at the end of this issue.)

Jemma Issroff

An Unusual Performance Optimization — The creator of HexaPDF goes deep to find the root of a performance issue with different fonts.

Thomas Leitner

RubyGems 3.2.6 Released — A small bug fix release. Update in most cases with gem update --system.

RubyGems Blog

📘 Articles & Tutorials

Testing Objects with a Functional Mindset — Some functional programming ideas could help improve the unit tests for your object-oriented code.

Joël Quenneville

▶  Chatting with a Rails Core Team 'Heavy Hitter' — Rafael França is a Principal Engineer at Shopify, Rails core team member, and has the most commits to the Rails codebase to his name (with even more than DHH). On this podcast he discussed how the Rails 6.1 release went and drops some hints about Rails 7.

Ruby on Rails Podcast podcast

A Better React/Rails Architecture — Spoiler: It’s about modularizing to allow each framework to fill its intended purpose in its intended manner.

Stitch Fix Technology

The Rails Upgrade Series — The guides go all the way back to 2.3 (I’d love to see usage statistics on the older guides) and up to 6.0, so if you need to upgrade for any version, check it out.

FastRuby.io

Rails 6.1 Adds Support for belongs_to to has_many Inversing — Because two ways are better than one, at least in this case.

Siddharth Shringi

Clubhouse.io - Cheerful, Collaborative Project Management

Clubhouse.io sponsor

Gradual Automation in Ruby — Writing code that tells people what to do, without actually doing it.

Tomasz Wróbel

▶  How to Use Devise with Hotwire and Turbo.js — Hotwire’s Turbo library intercepts forms automatically so Devise needs a few tweaks to work with it.

Go Rails

How to Use Mixins and Modules in Your Ruby Apps
Cleiviane Costa

When to Use Factory Bot's Traits Versus Nested Factories
Jason Swett

Rails 6.1 Allows Per Environment Configuration Support for Active Storage
Shashank

🛠 Code and Tools

TTY::ProgressBar — Display Progress Bars in the Terminal — A very flexible control you can customize and twist to whatever ends you want. You can also display multiple progress bars at once.

Piotr Murach

RouteTranslator 10.0: Translate Your Rails App Routes to Various Languages — Manage the translations of your app routes with a simple dictionary format. Works with Rails 5 and 6.

Enric Lluelles

Seamlessly Integrate Video into Your Ruby App — Integrating seamlessly into your mobile app's UI, Mux Video is an API-first platform that makes it easy to build beautiful video that streams on any device.

Mux sponsor

Thor 1.1: A Toolkit for Building Powerful Command-Line Interfaces — It hasn’t had a release in over a year but now supports Ruby 3.0.

Erikhuda

Loofah 2.9.0: Nokogiri-Powered HTML/XML Manipulation and Sanitization

Mike Dalessio

Derailed Benchmarks 2.0.0: Benchmarks for Your Whole Rails App“A series of things you can use to benchmark a Rails or Ruby app.”

Richard Schneeman

A Forward Proxy in 100 Lines of Code using Standard Libraries Only

James Moriarty

💻 Jobs

Senior Software Engineer at Loomly (Remote) — Loomly is the Brand Success Platform that helps marketing teams streamline online collaboration. We’re looking for a Senior Software Engineer to contribute to building our core product and help with ongoing maintenance.

Loomly

Experienced Ruby Developer (Rotterdam, Netherlands) — Join the #1 impact-investing crowdfunding platform in NL. Your code helps create sustainable jobs, install solar panels and more.

Lendahand

Find a Job Through Hired — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers.

Hired

ℹ️ Interested in running a job listing in Ruby Weekly? There's more info here.

💡 Tip of the Week

Open an IRB console within code using binding.irb

There are many popular debugging gems or IRB alternatives. These are typically packed with features and can be extremely useful tools. The main caveat to using them, besides learning their unique syntax, is having to install (and sometimes configure) them. If we're working in repos that don't have our favorite debugging gems installed, we have to adopt certain workarounds.

Perhaps less well known than gems like pry and byebug is the binding.irb feature of irb (as available in Ruby 2.4 onward). It allows us to open an IRB console from within the current scope. In this IRB console, we can call any methods or variables defined within the current scope as well as mutate state. Since IRB is installed with Ruby, there's no need to install any separate gems and it will work wherever we're running Ruby.

Here's an example of adding a binding.irb call to some simple code:

def func(input)
  a = 1
  binding.irb
  a + input
end

puts func(0)
$ ruby example.rb

From: example.rb @ line 3 :

    1: def func(input)
    2:   a = 1
 => 3:   binding.irb
    4:   a + input
    5: end
    6:
  7: puts func(0)


irb(main):001:0> a
=> 1
irb(main):002:0> input
=> 0
irb(main):003:0> a = 2
=> 2
irb(main):004:0> input = 3
=> 3
irb(main):005:0> exit
5

Voila! We get an IRB console from within our code. Not only can we see the values of our local variables, we can also change their values (which leads this program to print 5 instead of 1 as it otherwise would have). Any methods or variables available within the current scope can be accessed from this IRB console. As we see above, binding.irb will pause execution of our code, and exiting the IRB console will resume execution.

Next time you're debugging, give binding.irb a try!

This week’s tip was written by Jemma Issroff.