๐Ÿ‘‹ 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:

๐Ÿ‘ Our Community

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.

๐Ÿงฐ Vladimir Dementyev shared a new EvilMartians gem activerecord-slotted_counters.

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 Weekly published a new edition: Let's create a basic (useful) Ruby C extension

๐Ÿ—ž๏ธ Ruby LibHunt published a new edition of the Awesome Ruby Newsletter

๐Ÿ—ž Women on Rails published a edition Newsletter #40

Podcasts

Videos

๐ŸŽฅ Andrew Culver shared a video from Rails SaaS conference by Nadia Odunayo: Getting to One Million Users as a One-Woman Dev

๐ŸŽฅ Drifting Ruby published the video version of  This Week in Rails - Dec 2nd, 2022

๐ŸŽฅ 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.