Issue #9 - 5-11 September 2022
The one about organizing code
Hello,
Iโm Lucian (@lucianghinda on Twitter), and I am the curator of this newsletter.
Last week I launched Code Summaries, where I summarise technical articles about Ruby with code.
If you want to see a short version of this newsletter with only the content that has code, you can see it here. It is a presentation that has one tweet per slide uploaded to speakerdeck.com.ย
This edition was created with support from @adrianthedev from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and from @jcsrb, who sent me recommendations to include in the newsletter.
If you have any feedback or ideas about this newsletter, please reach out on Twitter or via email at hello@shortruby.com
๐ Xavier Noriaย shared a short explanation of how constants work in Ruby:

Constant identifiers and constant paths are just convenient interfaces into those maps. Helpful for common usage, and for giving the illusion of namespaces. The constants API gives a direct access to those maps, and allows other things like listing or deleting, for example. - Xavier Noria
๐ Thiago Massaย shared a new example of pattern matching with hashes:

He also shared the gist in case you want to play with it.
๐ Shino Koudaย shared a short code example of .map(&:to_s) and Brandon Weaver explain more in depth how this works:


๐ Thiago Massaย shared an example of how to use the Pin operator (^) pattern matching:

๐ Joel Drapperย shared an example of another underused operator, XOR:

๐ Lucian Ghindaย shared another example of using XOR:

But you should read the entire thread, as it has some excellent discussions about using these operators.
๐ Kirill Shevchenkoย shared two code samples explaining how |= is creating a new array instead of adding to the existing one:

๐ Joรซl Quennevilleย shared code about how to generate infinite series with Enumerator:

As the produce cannot be used to generate series where the input from each step needs the output of the previous step, then he showed how to add unfold to the Enumerator to achieve more:

And here is how he showed how to use that:

There are more examples shared in that thread.
๐ Lucian Ghindaย shared a thread about an opinionated way to learn Ruby:

๐ Emmanuel Hayfordย asked a smart question: How to explain Class.class being Class:

Here are some of the examples shared in that thread by Brandon Weaver, Lucian Ghinda, John Cheek, Ariel Caplan, Eric Halverson:

๐ Brandon Weaverย shared an experimental piece of code to implement proc_line:

๐ Joel Drapperย shared an example of how to use Phlex with ERB:

๐ Jean Boussierย shared their process to improve performance on string interpolation. Amazing read!

๐ Kevin Newtonย shared a quick command to help understand Ruby TRICK entries published by Yusuke Endohย here:

๐ Robby Russellย asked what is one main improvement for speeding up tests and received some very good answers.

Here are some of the responses shared by Brandon Weaver, Greg Navis, Konnor Rogers, Andrey Novikov, Benjamin Silva H, Andrew Ek, but please do go and read the entire conversation:
) > You can move the database to a memory based file system (source: [@gregnavis](https://twitter.com/gregnavis/status/1568489038025265152?s=21&t=1Swh-mDlfNdSl2FrIUyKcA)) > Does factories -> fixtures count as small? (source: [@RogersKonnor](https://twitter.com/rogerskonnor/status/1568406745323552769?s=21&t=1Swh-mDlfNdSl2FrIUyKcA)) > Disabling logging speeds up tests quite noticeably (source: [@Envek](https://twitter.com/envek/status/1568405606830309376?s=21&t=1Swh-mDlfNdSl2FrIUyKcA)) > Sometimes more junior devs don't realize that in many cases you don't need to create records in order to test them, in many cases you can replace create(: for build(: in factories and it works (source: [@bsilva96](https://twitter.com/bsilva96/status/1567913277748813824?s=21&t=1Swh-mDlfNdSl2FrIUyKcA)) > In many of the codebases I've been in, it's a relatively small number of very slow tests that, if fixed or reworked, can speed up the whole test suite quite a bit. So finding the 5-10 slowest tests and deciding what to do with them can sometimes do the trick. (source: [@ektastrophe](https://twitter.com/ektastrophe/status/1567912675279097862?s=21&t=1Swh-mDlfNdSl2FrIUyKcA))](https://archive-assets.shortruby.com/assets/issues/fdd60b51ecc7306269830aae80987a704e515ff7c94c152652152a6264b2c3d6.png)
๐ Thiago Massaย asked a question and shared a code sample about the ampersand Ruby idiom:

And along with this question Thiago shared a code sample:

He received some inspiring responses, read the entire conversation. Here are two of them:



๐ Joel Drapperย shared a new update for Phlex.fun showing support for conditional CSS classes:


๐ Matt Swansonย shared code about how to use modules to organize features:

Here are some interesting replies, but I really recommend you to read the entire conversation (for people not using Twitter use this)as it has great sugestions and some great explanation for various styles:



๐Shino Koudaย asked what is the result of executing the following code:

Brandon Weaverย shared explaining how [] works for arrays and hashes:
![`[]` is a method, `something.[](index)`, so the result would be `"a"`. This is similar to other operators like `1 + 2` is actually `1.+(2)`. That said, not common use, `dig` or `fetch` or `slice` would be more common if you're avoiding `[]` directly.](https://archive-assets.shortruby.com/assets/issues/55e00b5eb0e377d6f874bcfffa6523ceadfdfc31542859e562a574b8aabb8ddc.png)
๐ Kirill Shevchenkoย shared a code sample about how to use lazy enumerators:


๐ Joe Masilottiย shared a sample code showing how to add a hidden field to the button_to helper:

If you read so far and you like the content, maybe you take into consideration sharing this and subscribe:
Related (but not Ruby specific)
Vinicius Stockย shared two VSCode tips for people working with Sorbet:

Joe Masilotti ๐ย shared asked about Ruby and Rails communities and he received a lot of replies:

Here are some of the communities shared in the conversation:
Kasper helps your Ruby&Rails - on Discord
GoRails - on Discord
Hotwired - on Discord
Ruby on Rails - on Discord
Stimulus Reflex - on Discord
Avo - on Discord
Ruby on Rails - on Discourse
Ruby on Rails Link - on Slack
Ruby Lang - on Discord
Ruby on Rails - on Twitter Communities
Aprende RoR - on Discord
Official Ruby on Rails - on Discord
Ruby - on Discord
Bullet Train - on Discord
Bridgetown - on Discord
New projects built with Ruby
๐ข Julian Rubischย shared that they launched railsreviews.com - Reactive Rails Reviews.
๐ข Jeremy Smithย shared launched railsinspire.com - A curated collection of code samples from Ruby on Rails projects.
Articles and Videos
RubyKaigi 2022 slides and more
Colby Swandaleย shared from his talk at RubyKaigi about Adding Type Signatures into Ruby Docs
Yusuke Endohย shared a Cookpad code puzzle that was created for RubyKaigi, but anyone can play it now: https://ruby-puzzles-2022.cookpad.tech
Jeremy Evansย shared slides from RubyKaigi presentation: Fixing Assignment Evaluation Order
Koichi ITO shared their slides from RubyKaigi about Making Rubocop Super Fastย
Takashi Kokubunย shared their slides from RubyKaigi about Towards Ruby 4 JIT
Courses or Books
๐ Noel Rappinย shared that the second version of his book Modern Front-end Developmen for Rails is now updated to work with Rails. Buy it here (PragmaticProgrammers shared on twitter also a discount code)
๐ David Colbyย shared that they made free their book Hotwired ATS, that is teaching how to build a complex Rails 7 application with Turbo, Stimulus, CableReady and Stimulus Reflex.
Something to read
Newsletters
Any Cableย shared a new issue of monthly Any Cable updates: Any Cables Monthly #2 โ August, 2022
Greg Molnarย shared a new edition of This Week in Rails created by Emmanuel Hayford.
Andrew Masonย shared they released a new Ruby Radar issue #67 - New Rails Release!
Ruby Libhunt released a new version of their #329 Awesome Ruby newsletter.
Articles
Nate Berkopecย shared an article written by Jemma Issroff about how to find faster in a sorted array using bsearch
Sam Rubyย shared a good tutorial about how to use Turbo Stream and Stimulus with a Rails app on Fly
The Ruby Devย shared installing Ruby on AWS EC2 with Cloud Formation
Something to watch ๐ฅ or listen ๐ง
Videos
๐ฅ Julian Rubischย shared a video showing how he is using CableReady::Updatable and Turbo forms to implement a previewable text area. See it โ Public Building RailsReviews - #1 Preview Component
๐ฅ Vladimir Dementyevย shared a new episode of AnyCasts where deploys AnyCable to Fly. See it โ Ep. 6: Learn to Fly.io with AnyCable
๐ฅ Hexdevsย shared a new episode of Open Source Thursdays about an introduction to how Faker works and how to contribute to it. See it โ Letโs Faker Together: a Ruby library for generating fake data
๐ฅ Drifting Rubyย shared the video version of This Week in Rails. See eit โ This Week in Rails Sept 10th, 2022
Audio & Podcasts
๐ง Drew Braggย shared a new episode about Coding Coders who Code with Ernesto. Listen โ Episode 10 - Ernesto Tagwerker
๐ง Therubyonrailspodcastย shared a new episode of The Ruby on Rails podcast about RubyConfMini: Listen โ Episode 434: All Things RubyConf Mini (Brittany + Jemma)
๐ง Fullstack Rubyย shared a new podcast about How to manage ruby apps dependencies. Listen โ Episode 6: How do you manage Ruby Application Dependencies
๐ง Ruby For Allย shared a new episode about programming with ADHD. Listen โ Programming with ADHD
๐ง Joรซl Quennevilleย shared a new episode of BikeShed with @EebsKobeissi. Listen โ 353: Mental Models
๐ง Remote Rubyย shared a new episode about the new Hatchbox.io V2. Listen โ Episode 196 โ The brand new Hatchbox.io V2
Gems, Libraries, and Updates
Aaron Pattersonย shared a release of Rack 3.0.0.rc1 and invited anyone to test it. Read the latest Changelog here.
Mike Dalessioย shared the latest version of sqlite3 gem is out and it ships with precompiled sqlite. Read the Changelog here
Rob Sanheimย shared a gem that helps running parallel_tests:
It will run parallel on multiple CPU cores. ParallelTests splits tests into even groups (by number of lines or runtime) and runs each group in a single process with its own database.
ๆ็ฌย shared that Ruby 3.2 preview 2 is released. See the announcement here. Ruby 3.2 has WASI based WebAssembly support, Regexp timeout, YJIT arm64 support and many more things.
Hiroshi Shibataย shared they released Ruby build with support doe Ruby 3.2.0 preview2. See the release
Koichi Itoย shared rubocop performance 1.15. Check release notes
Konnor Rogersย shared declarative shadow DOM components in Rails. See the code here.
Ruby Lib Huntย sharedย for creating chains, similar to chaining with then. The source code of this library is here. Here is a code sample:

Michael Nikitochkinย shared a new version of the toxiproxy library that is a TCP proxy to simulate network and system conditions for chaos and resilience testing. See the project here and here is an example:

This was a long issue as there was a lot of great content that I discovered in Ruby community. I started to follow what is happening on Reddit communities so I will probably start bringing content from there.
Please consider sharing this on social media or with your colleagues: