#​703 — May 16, 2024

Read on the Web

Together with  pgAnalyze

Ruby Weekly

Ruby 3.4 Preview 1 Released — I love it when the first preview of a new Ruby version drops. It makes it easier to get playing with the new features and reminds me of Christmas.. 😂 It’s a preview so don’t throw it into prod (unless you’re Shopify) but it’s a good one to test against with a key change to how string literals now behave (I anticipate this could break a few dependencies..)

Yui Naruse

Free eBook: Advanced Database Programming with Rails and Postgres — Learn about subqueries, materialized views, and custom data types in Postgres and Rails. We walk through realistic real-life examples, translating first into SQL, and then into Rails code. Every example comes with source code so you can follow along.

pganalyze sponsor

📄 Articles, Tutorials & Videos

GitHub's dependabot-core is Now Open SourceDependabot is a tool GitHub used to monitor the dependencies of projects hosted there (and create automated PRs to update them). It’s always interesting to see them open source a key part of their infrastructure – especially when it’s mostly written in Ruby!

GitHub

Why You Should Nest Modules in Ruby — Justin demonstrates a couple of gotchas you can avoid by nesting modules, if at the price of a little added verbosity.

Justin Toniazzo

Developer’s Guide to Heroku Dynos — Which dynos should you use, and how many? (TLDR: Don’t use Perf-M!).

Judoscale sponsor

A RailsConf 2024 Recap — Kevin had a great time at RailsConf last week and he covers some of what he saw there. Separately, he’s put together four things to take away from RailsConf 2024.

Kevin Murphy

📄 A Class Pattern to Work with API Requests with an Async Approach Mykola Zozuliak

📄 How We Used a Custom Enumerator to Fix a Production Problem Thiago Araújo Silva

📄 Hidden Feature of Turbo: Stream Actions Inside Regular HTML Radan Skorić

📄 A Less Painful Way to Work with Shopify's GraphQL API in Ruby Kirill Platonov

📄 Creating a Progress Bar in a Hanami App with HTMX Krzysztof Kamil

📄 Creating Forms in Rails with Simple Form Thomas Riboulet

🛠 Code & Tools

Vernier 1.0: A Next Gen CRuby 3.2+ Profiler (And How to Use It!) — A sampling profiler that can track multiple threads, GVL activity, GC pauses, idle time, etc. We linked to it not long ago, but it’s reached v1.0 and there’s now ▶️ a fantastic talk by its creator on what it does and how to use it.

John Hawthorn

The Git Gem 2.0: A git Wrapper for Use from Ruby — Takes the simple approach for wrapping calls to the usual git binary.

Scott Chacon et al.

🌳 Need to Upgrade to Ruby 3.3 on a Budget? Try Bonsai by FastRuby.io — Stuck on Ruby 2.7? Stop postponing your upgrade, ship it with our fixed-cost monthly maintenance service. 🚀

Bonsai By FastRuby.io sponsor

Strong Migrations: Catch Unsafe Migrations in Development — Detects potentially dangerous operations and prevents them running by default. Supports PostgreSQL, MySQL, and MariaDB.

Andrew Kane

Promptcraft: Try New System Prompts on Your AI Conversations — A Ruby-powered CLI tool for replaying a user/AI-agent conversation over and over but with a new system prompt each time so you can hone things until you get the end results you want.

Dr Nic Williams

💡 Quick tips..

Tip 1: On Twitter, Dr Nic Williams shared a tip of how to make systems like ChatGPT return better code by being more specific in your system prompts. For example:

When giving Ruby code snippets, use modern Ruby 3.3 syntax, especially for hashes and method signatures with named parameters.

I followed up with a half joke based on my own experiences where LLMs ignore other modern Ruby constructs and idioms, which leads us to...

Tip 2: If you have an array, say, of items and you want to create a hash with the keys being the unique values and the values being the number of times those values appear in the array, you might do something like this:

array = [1,2,2,3,4,4,4]
array.each_with_object(Hash.new(0)) { |i, h|
  h[i] += 1
}

Or, perhaps:

hash = Hash.new(0)
array.each { |i| hash[i] += 1 }

Since Ruby 2.7, however, you can use array.tally! It's made my Advent of Code solutions far less verbose.. ;-)

Tip 3: A simpler tip lies at the heart of tip two. Skim Ruby's docs from time to time! Whenever I check out the docs for Enumerable, I'm reminded of something I fail to remember in my day to day work. Have a browse and you might find your own useful shortcuts to share with your team.