#​587 — January 20, 2022

Read on the Web

Ruby Weekly

Proposal to Merge WASI-Based WebAssembly Support into Ruby — There have been experiments before, but having WebAssembly as an officially supported target for Ruby would open up some interesting use cases. While this is exciting news, it’s very early days and with a variety of expected limitations (e.g. around threading). A story we’ll keep an eye on, for sure, and hopefully a headline feature for Ruby 3.2.

Yuta Saito et al.

🎉  Happy 10th Birthday to Sidekiq, the Background Job Processor — A true Ruby success story! The creator of the hugely popular Sidekiq background job system celebrates a decade of work (to put it in perspective, DynamoDB also turned 10 this week!) by looking back at the decisions that made it possible and potentially handing the project over to the community in the future.

Mike Perham

Spend More Time Building with Scout APM — Scout is a lightweight application monitoring service built for modern development teams. With a transaction based pricing model and unlimited seats, anyone on your team can be a performance expert for a low cost. Start your 14-day free trial today.

Scout APM sponsor

Reducing Method Calls by 99.9% by Replacing Thread#pass with Queue#pop — If you work with threads at all, you’ll enjoy this as it digs into some useful points about multi-threaded flow control in Ruby and when different approaches fit best.

Maciej Mensfeld

On The Future of 'Adopting' Ruby Gems — The RubyGems project wants to introduce a formal process to allow owners of gems to hand the stewardship of those gems to new owners. Here’s a bit more about how it could work in practice.

Aditya Prakash (RubyGems)

IN BRIEF:

Jobs

Backend Engineer | Remote within CET (-3/+3 hours) | Full-Time — Europe's leading business finance solution. You will help us simplify everything from everyday banking and financing, to bookkeeping and spend management.
Qonto

Senior Rails Engineer @ Nebulab (Remote) — Join our distributed team and build high-volume eCommerce applications in a workplace made by developers for developers.
Nebulab

Find Ruby Jobs 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

📕 Articles & Tutorials

On How FastRuby Uses RuboCop and StandardRB — FastRuby is a (commercial) Rails upgrading service so tooling around enforcing rules and code style standards is unsurprisingly of utmost importance to them.

Ariel Juodziukynas

Build a Minimal Feature Flags Manager in Under An Hour — Feature flags provide a neat way to enable/disable potentially in-progress or prototype features for subsets of your users. Want to roll your own such system for a Rails app? It’s possible to do without much hassle.

Remi Mercier

Build Time Series Data Apps with Ruby and InfluxDB — Get InfluxDB set up and build your real-time app with this tutorial.

InfluxData sponsor

Looking at Ruby's Splat Operator — A nice summary of what the operator does and why it can be confusing (as the author notes, “it does two things that are the exact opposite of each other”).

Sami Birnbaum (thoughtbot)

How PlanetScale's Rails Test Suite Runs in 1 Minute on Buildkite — Essentially running a LOT of parallel workers and making sure test data was as efficient as possible – meaning you could do this, too.

Mike Coutermarsh

Maintainable Rails System Tests with Page Objects — An interesting way to clean up system tests with classes that represent each page that has some nice maintainability examples.

Josef Strzibny

What You Can Learn by Merely Writing a Programming Language Changelog — We linked to Victor’s excellent Ruby 3.1 changelog two weeks ago. Now he reflects on what he learned, loved, and loathed in creating it.

Victor Shepelev

Stop Paying Tech Debts, Start Maintaining Code“Every time you touch some code, clean something up.”

Jesse O'Brien

Everything You Need (Nothing You Don't) to Build Video for Ruby

Mux sponsor

▶  Discussing WNB.rb with Emily Giurleo and Jemma IssroffWNB.rb is a Ruby community and meetup focused on women and non-binary folks and you can learn more about it in this show.

Remote Ruby podcast

Five Easy to Miss PostgreSQL Query Performance Bottlenecks
Paweł Urbanek

Configuring Rails System Tests for Headless and 'Headfull' Browsers
Josef Strzibny

🛠 Code & Tools

JRuby 9.3.3.0 Released (Now with M1 Support) — The latest Ruby 2.6.x compatible release of the popular JVM-based Ruby implementation. The big news is added support for M1 processors, a.k.a. Apple Silicon.

JRuby Core Team

Commontator 7.0: A Rails Engine for Comments — As an engine it provides its own models, views and controllers which you can then customize to your own commenting needs.

Learning Machines Lab

online_migrations: Catch Unsafe Postgres Migrations in Development and Run Them Easier in Production — Writing safe migrations can be difficult, especially at scale and in production, so this gem will stop problematic migrations from running and supply suggestions on how to run them safely.

Dima Fatko

Reek 6.1: A High Level 'Code Smell' Detector for Ruby Code
Timo Rößner

💡 Tip of the Week



File Methods: Part One

Many of us are familiar with how to move around different directories or files when we're using our favorite editors. Our Ruby programs, or gems we use, often need to do similar movements to different directories, or to load different files. How can Ruby programs know which directories a certain file is in, or load other files?

__FILE__

For starters, __FILE__ is a Ruby constant which gives us a String represenation of the path to the current file, from where it was called. For instance, if we have a file example.rb which looks like this:

puts __FILE__

and I run it, I'll get

$ ruby example.rb
example.rb

If we move one directory up though, so that example.rb is now in ruby_weekly/example.rb, and run it, we'll see the path including the ruby_weekly directory:

$ ruby ruby_weekly/example.rb
ruby_weekly/example.rb

What if we need the full filepath of a file on a machine, not just the one we're running from?

File.expand_path

File.expand_path will give us the full filepath. For instance, if we change example.rb to look like this:

puts File.expand_path(__FILE__)

and run it, we'll see

$ ruby ruby_weekly/example.rb
/Users/jemmaissroff/ruby_weekly/example.rb

This week's tip is laying the groundwork for us to dig into File.join and File.dirname (including a new Ruby 3.1 arg) next week!

This week’s tip was written by Jemma Issroff.