👋 Short Ruby News - edition #21

Briefly about everything in Ruby world

This edition was created with the help of @adrianthedev/@[email protected] from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and @jcsrb.

You can jump directly to one of the following sections if you like:

More content: 🎥 🎧 🗞 (articles, podcasts, videos, and newsletters)

👐 Our Community

👐 Ruby On Rails shared about Ruby scales:

Rails scales. From HELLO WORLD to The Entire World.

👐 Someone asked the following question on /r/ruby:

I think it is worth considering if we want to create more contents that is not only for people coming to Ruby from other languages but also learning Ruby as their first programming language.

👉 All about Code and Ruby

👉 Jason Swett asked a question about their pain points: 

Rails devs: Over the years, what are some things that you've been consistently unhappy with about your OWN code? For example, for years I couldn't figure out how to fix my nasty 800-line models...in a way that was actually an improvement. What about you?

Here is a summary of the answers:

  • “over investing in interactors” (@dpaola2)

  • “Policies + permissions sneaking into multiple places across the codebase.” (@joemasilotti)

  • “Handling API validation without leaning too much on AR validations.” (@timcheadle)

  • “Controllers with too many complex options and custom methods” (@Diragor)

  • “How to break down code which feels like it should belong in the model. That and callbacks.” (@bmozza)

  • “Front-end code organization. Asset management. Deployment. Automating accessibility testing. HTML emails” (@TALlama)

  • “File structure, mostly when there si multiple features and country conditions” (@barroetald)

  • “I often find myself having to create custom serializers if i dont want to .includes multiple relations that im not using” (@bc2rieg)

  • “nested serializers and field selection is the absolute worst” (@eleslovaco)

👉 Eric Berry shared a sample code in replit about creating a color palette in Ruby:

Need a color palette for your charts/graphs in Rails? I wrote up a class that will generate the colors for you with the following code: ColorPalette.generate(30) Try it out at

👉 Shopify Engineering shared a thread about how they handled Black Friday and Cyber Monday:

📈We served 75.98 Million requests per minute to our commerce platform at peak. That’s 1.27 Million requests per second!

You should read the entire thread for more impressive stats. When people ask if Ruby scales show them this.

👉 Dave Copeland shared a piece of code in Ruby showing how to have a method accept multiple blocks:

I think the conversation between Peter Solnica, James Adam, Ryan Bates, Dave Copeland, and Brandon Weaver about methods of accepting multiple blocks is worth reading on ruby.social.

If you don’t want to read it all, at least look at this code snipped by Brandon Weaver, where he implemented function objects with stack and compose blocks showing the flexibility and beauty of Ruby.

👉 Matt Swanson shared a view component concept: Fallback slots

ViewComponent pattern/concept: "Fallback slots" It's really powerful for building components that can support an excellent 'happy path' but also still be ergonomic for dropping down to lower-levels Small detail is naming the slot and argument the same ("title")

👉 Emmanuel Hayford shared a code sample about Active Record for async queries:

Rails 7.1 will give you a lot of possibilities: Active Record added an API for general async queries. Soon, you’ll be able to run aggregates and `find_by_sql` asynchronously. So you can do stuff like:

👉 Noel Rappin asked how the community feels about static typing in Ruby:

Here are some answers:

“I'm hard-pressed to think of it as significantly better than documenting the type or using a convention around naming UNLESS the entire codebase uses it and opting out is not an option. In that case, "lean on the compiler" refactoring is awesome and the only thing I miss from Java.” (@[email protected])

“it’s the future. Having a compiler tell you about a type bug BEFORE your users do is a lifesaver. I’ve tried using Sorbet with mixed results. Leaning more on dry-types and dry-schema these days, as they’ll give runtime type validations. The code that uses these gems _feels_ safer” (@[email protected])

“I want to write YARD and have it checked, but if I have to spend time trying to figure out the incantation needed to convince the typing system what I’m doing is correct, it’s too intrusive. If I need to add boilerplate, it’s too intrusive.

I think YARD + sord + steep is potentially a good synergy but I wish it were more automatic than it is.” (@[email protected])

“for me it's far more bound to the domain complexity, a lot of which self inflicted through polymorphism or polymorphic associations among other things. I find it to be very useful at boundaries, and less useful in the inner domains. Boundaries, like packs / Packwerk might provide, are domain gates where context is more easily lost on how to interact.” (@[email protected])

These were just a few replies, but the conversation is bigger and worth reading it all. People share a lot of experiences and cases from both sides.

👉 Ayush shared that the book they are working on is almost ready:

At long last, The Rails and Hotwire Codex is complete and will drop on 15th December, 2022. It's funny how my deadlines went from mid summer, to late summer, to early Q4, to before the end of the year 😂. Complications arose, ensued, were overcome.

👉 пан Zverok shared a code sample about unpacking numbers into binary order of magnitude and prefixes:

A small excercise in modern (3.2-pre 😁) Ruby, inspired by https://t.co/wQora4Iidj Helper module for "unpacking" numbers into binary orders of magnitude + prefixes

👉 Jakob Skjerning shared a sample code showing how to alias attributes in Active Record:

#TIL You can alias attributes in ActiveRecord, and it will even work for database queries #ruby #rails #activerecord

👉 Drew Bragg shared a code sample showing how Ruby can work with emojis:

I blame @schwad_rb for this cursed #ruby code

👉 Joel Drapper shared a preview of what might be included in the phlex-markdown:

👉 Greg Navis shared a thread about Ruby tips about partitioning and grouping arrays:

1️⃣ partition returns two arrays: items that meet and don't meet the condition passed in via a block In the example below, we classify clients on whether they have a free or paid account. There's also group_by for more complex cases ...

Please read the thread, as it has an example also about group_by.

👉 Ryan Bates shared that it is hard following and reading Ruby code with mixins:

Anyone else have difficulty reading Ruby code that makes heavy use of modules? I have no idea where a given method is defined or what methods are available in a given context.

It would be good to read the replies because many people share why the code is complex to read when using many modules as mixins.

👉 Flavio shared a thread about various Heroku alternatives:

Here are some alternatives proposed:

  • replit.com - like a playground suitable for test projects. Each app gets a repl.co subdomain

  • glitch.com - a playground for Nodejs apps and simple sites

  • vercel.com - a hosting option for Nodejs with a generous hobby plan

  • netlify.com - for hosting static sites, they have a great free plan. No backend

  • CloudFlare Pages - similar to Netlify, no backend but with unlimited bandwidth

  • render.com - have a free plan, static site hosting can run Node/Python/Rust/Go/Ruby and much more with a free database

  • railway.com - free started plan, can add multiple apps, with database and support for SvelteKit, Next, Vite, Rails, Nuxt …

  • supabase.com - with a free plan of up to 2GB bandwidth and 1GB file storage for the database, it also has some support for functions using Deno. They have a migration tool for data from Heroku to supabase

  • fly.io - has a free plan great for experimenting and support for entirely hosting your web app, including database, load balancing, monorepos, and more

  • dokku - transforms a server/VPS into a Heroku clone

👉 Sandi Metz announced a 40% discount for the 99 Bottles book, which seems to end on Monday night:

The 99 Bottles of OOP 40% off Half-Birthday Sale ends tomorrow night! Next sale in June on our birthdays--that's a long wait. 🎉 now

If you have read so far and you like the content, maybe you take into consideration sharing this and subscribing:

🧰 Gems, Libraries, and Updates

🧰 Marc Anguera Insa shared a new project Tonic - Self meta-described collections framework. It takes a collection defined in an YAML or JSON and automatically generates a beautiful website build with Middleman, Ralix and Tailwind.

🧰 Alexandre Ruban shared a new gem action_markdown that helps to work/displaying markdown content:

I love @github's Markdown editor when writing issues/pull requests. 😍 I would love to have this feature out of the box for Ruby on Rails applications. This is why I released my first gem action_markdown which aims to reproduce GitHub's editor.

If you are looking to use markdown, here are some other possible options markdown-rails or html-pipeline or phlex-markdown

🧰 Nate Hopkins published hopsoft/reflex_behaviors: Pre-built easy-to-use reactive TurboReflex behaviors for Rails/Hotwire apps.

Slotted counters help to reduce contention on a single row update in case you have many concurrent operations (like updating a page views counter during traffic spikes)

🧰 Ngan Pham shared a PR that was merged to Rails and fixes the deadlock caused by using a fiber inside a transaction: Make AbstractAdapter#lock thread local by default

🧰 Jeremy Evans shared a new version for Sequel 5.63.0 Released Read the changelog

🧰 Aaron Patterson shared a PR they created and merged to Ruby that will Speed up IV writes

🧰 Lewis Youl shared a PR for Turbo that allows it to respond with turbo streams to GET requests Allow Turbo Streams with GET via data-turbo-stream

🤝 Related (but not Ruby specific)

🤝 Rose W shared small things that can have a lot of impacts in our daily work:

A few little things that can have a lot of impact at work: - Remember to say thank you - Highlight other people’s good ideas and work for them (after checking they are ok with public praise) - When someone helps you tell their boss you appreciated it

🤝 Jason Swett shared a programming tip:

Programming tip: Try to use as few conditionals as possible. They often make code harder to understand.

🤝 Bijan shared a tip about submitting an html form tag without Javascript from outside the form. I know this is not something new but I think it is good to remind ourselves about this:

Did you know that you can submit an html form without javascript from outside the form tag by referencing the form="dom_id"?

🤝 Celso De Sa shared an explanation for Liskov Substitution in Ruby explained by ChatGPT:

Ever struggled to grasp what Liskov Substitution Principle really mean? I asked #GPT3 to explain it with an analogy and code: "The Liskov Substitution Principle is like a recipe. If a recipe calls for butter, you can substitute it for margarine and still get the same results.

🤝 Adam Hess shared a new project to explore Ruby WASI:

I built a Ruby Explorer using Ruby WASI https://t.co/e3VTQIcagw

More content: 🎥 🎧 🗞

Slides

Jeremy Evans shared their slides from RubyConf 2022 about Helping Redistrict California with Ruby

Noel Rappin shared their slides from RubyConf 2022 about In Defense of Metaprogramming

Newsletter

🗞 Ruby on Rails published a new edition of This Week in Rails curated this week by Wojciech Wnętrzak

🗞 Ruby Radar published a new edition: Ruby Radar #79

🗞️ Ruby LibHunt published a new edition of the Awesome Ruby Newsletter

🗞 Women on Rails published a edition Newsletter #40

Podcasts

Videos

🎥 Tom Stuart shared a video where they show they could replace Struct with Data.define without incidents: Making a WebAssembly interpreter in Ruby, part 17: Ruby 3.2, branch targets and function calls

Articles

Avo published the second part of their series of articles about How Successful Agencies Ensure Dev Happiness Part 2

Ryan Bigg published a new blog post about Hanami 2.0

 Kevin Newton published the second article about YARV, the virtual machine of CRuby:  Advent of YARV: Part 2

Reply

or to participate.