#​565 — August 12, 2021

Read on the Web

✍️ I wouldn't normally do this, but last week's issue was so strong that if you missed it, you should step back and check it out :-) We covered stuff like Stripe's Ruby compiler, the Fukuoka Ruby Award, Ruby's future debugger, and even a new Nokogiri release. This week is somewhat quiet in comparison! :-)
__
Peter Cooper, editor

Ruby Weekly

Opal 1.2: The Ruby to JavaScript Compiler Goes Ruby 3.0 — Well, almost. Opal is a long standing and interesting project that lets you build front-end experiences for the Web in the language you already know and love. This is a significant release. Want to play? Try it live here.

Opal Team

Ruby's Hidden Gems: BulletBullet provides a way to monitor your app’s database queries to find inefficiencies (N+1 queries, unused eager loading..) you can resolve.

Fabio Perrella

Troubleshoot Ruby App Performance with End‑To‑End Tracing — Datadog’s APM generates detailed flame graphs to help you identify bottlenecks and latency. Navigate seamlessly between Ruby app traces, logs and metrics to troubleshoot application performance issues fast. Try Datadog APM free.

Datadog APM sponsor

QUICK BITS:

  • Gift Egwuenu shares the latest monthly update for the RubyGems project.

  • GitHub has made its Codespaces cloud-based IDE feature more generally available and is, apparently, using it in-house for much of its development work: "Over the past months, we’ve left our macOS model behind and moved to Codespaces for the majority of GitHub.com development".

  • In other GitHub news, go to any GitHub repo and press .

▶  Discussing Ruby JIT and MJIT — Curious about how just-in-time compilation factor into the future Ruby performance story? Takashi Kokubun (aka k0kubun) has spent a lot of time in the JIT weeds and joins the Rogues to explain the ups and downs.

Ruby Rogues Podcast podcast

▶  Hotwire Turbo Replacing Rails UJS — Rails UJS wasn’t the most-loved part of the framework, but it did supply some cool interactions out of the box, so wouldn’t it be nice to use the new hot(wire)ness to get the same results?

Drifting Ruby

Jobs

Full Stack Engineer (Rails, New York) — Dovetale helps Shopify merchants like KontrolFreek and Italic grow their creator community. Built in NYC and backed by Uber founders.
Dovetale

Principal Software Engineer (Remote in the US) — Join our creative, remote-first team to help design & build a platform that is revolutionizing the commercial asset service industry.
Decisiv

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

Kubernetes & Rails: A Definitive Guide — A production-focused guide that covers domain names, secrets, logging, background and cron jobs, migrations, and other topics that will start you down the path to Kubernetes deployments.

Marco Colli

Building a Programming Language in Ruby: Part 2 — In this second part of a three-post series (here’s part one again), the ‘Stoffle’ programming language is completed to a runnable (but simple) stage where functions, loops, variable scope, and other concepts are put into the code.

Alex Braha Stoll

A Guide for Preloading Associations in Rails — While Benito does cover the basics, he also explains many of the more esoteric methods to preload nested and other associations.

Benito Serna

React on Rails: Building a Simple App — Learn how to create a React app from scratch and integrate it with a Rails back-end via webpacker.

Honeybadger sponsor

An Object-Oriented Example — Noel wants to push OO patterns and design so he creates and defends a class abstraction that results in more, but cleaner, code.

Noel Rappin

Five Turbo Lessons I Learned the Hard Way — Turbo is hot out of the oven, which means parts of it (and its docs) may be a bit ‘raw.’

David Eisnger

▶  Object Modeling and Testing Techniques with Lee McAlilly — A discussion on how to decide where to put your code, the benefits of good naming conventions, and how testing can help you figure out what to do and how to do it.

Rails with Jason Podcast podcast

▶  Load Testing Rails Apps with JMeter ft. Milap Neupane — There’s a blog test on the topic if you prefer. Apache JMeter is an open source Java(!)-based app for load testing of functional behavior in apps.

Ruby Rogues Podcast podcast

🛠 Code & Tools

FastImage: Find the Size or Type of an Image From Its URL, Quickly — Somehow it’s been six years since we linked this, but it’s still getting releases. The idea is it uses small byte range scoped HTTP requests to grab as little of an image to figure things out.

Stephen Sykes

Resque 2.1.0: The Redis-Backed Ruby Background Job Library — It’s the one that isn’t Sidekiq, and this is its first release since 2018.

Resque

Send Logs from Your Ruby and Ruby on Rails Applications to LogDNA

LogDNA sponsor

Statesman 9.0: A State Machine Library — Takes a different approach to most other state machine libraries by having you define state behavior in separate classes that are then instantiated from within your other classes. This week’s release adds Ruby 3 support.

GoCardless

pusher-fake: A Fake Pusher Server for Development and Testing — If you’re using Pusher to add real-time mechanisms to your app, this may come in handy during development.

Tristan Dunn

Elasticsearch Integrations for ActiveModel/Record and Railsv7.2.0 just dropped.

Elastic

💡 Tip of the Week



prepend

We'll continue our brief Tip Of Week series around using code from a module by learning about prepend. Last week, we learned about include, and how it inserts a module into the ancestors chain directly after the class which includes it.

prepend uses the same syntax as include but works differently - it inserts a module into the ancestors chain directly before the class which includes it. Let's take a look:

module ExampleModule
  def example_method
    "This is defined in the module we're prepending"
  end
end

class ExampleClass
  prepend ExampleModule
end

ExampleClass.new.example_method
=> "This is defined in the module we're prepending"

Now if we look at the ancestors chain, we'll see that ExampleModule precedes ExampleClass. This is the exact opposite of what we saw last week with ExampleModule succeeding ExampleClass:

ExampleClass.ancestors
=> [ExampleModule, ExampleClass, Object, Kernel, BasicObject]

As we learned when discussing ancestors, this means that Ruby will first look for a method defined on ExampleModule, and if it's not defined there, it will continue to traverse the list of ancestors, looking next at ExampleClass (our class itself).

This means using prepend will cause the methods defined on the module we're prepending to trump methods defined on the class itself.

module ExampleModule
  def example_method
    "This is defined in ExampleModule, which we're prepending"
  end
end

class ExampleClass
  prepend ExampleModule
  
  def example_method
    "This is defined in ExampleClass itself"
  end
end

ExampleClass.new.example_method
=> "This is defined in ExampleModule, which we're prepending"

prepend is commonly used in cases where it makes sense for a module to override a method defined in a class. Examples of this might be when a module needs to set something up in the initialize method, but the initialize method of a class itself doesn't call super. The initialize method in the module can do whatever setup it needs, and then call super to execute the class' initialize method.

We'll learn about extend next week!

This week’s tip was written by Jemma Issroff.