Issue #2 - 18 - 24 July 2022
You can read this newsletter online here. It might be too long for some email clients.
If you like it and have suggestions of people working with Ruby and sharing interesting stuff on social media, please find me on Twitter @lucianghinda and tell me about them.
If you want to receive a weekly email in your inbox use the button to subscribe:
Xavier Noria is starting a good conversation about project management:
David Copeland is talking in a thread about tests and how to make sure that the tests will break if the code does not work:
He also created a new gem Confidence Check that can help with isolating the setup needed to assert something in the code and clearly display when the setup is failing or the test itself is failing.
Andy Croll launched a fantastic initiative to help people gen on board with Ruby or develop their careers. I joined as a mentor as you should do it too at https://firstrubyfriend.org.
He is also inviting us to share the website in communities where people are learning Ruby so that they can ask for help and be paired with a mentor.
Alexandre Ruban explained how to use ActiveSupport::Deprecation.warn when changing the public API of a an object:
(not Ruby but more web related) Dave Thomas shared a TIL about drawing a vertical bar using flex:
Jean Boussier shared that he did an improvement in Ruby and increased the performance of `String#«` with 30%:
You should read the entire thread where he also explains more about this improvement and how it will speed up Rails 7.1 and Ruby 3.2.
Later he shared more benchmarks where the String#« optimisation brings 65% speed for UTF-8.
Emmanuel Hayford shared an example about using refinements in Ruby:
Refinements in Ruby are powerful. Here's an example illustrating Ruby's dynamism. You can conditionally break out of a "refinement" with the `super` keyword. This means more control over when and how you want to manipulate core classes.
Steve Polito shared an example of Rails helpers for working with date and time:
Cezar Halmagean shared a tweet with advice about not using comments when writing Ruby code.
You should read the entire discussion as it has some interesting examples of using or not using comments.
It also has this code sample shared by Joel Drapper to show how to encode a comment explaining a restriction imposed by AWS Media Converter in some cases to have width and height as even numbers:
Joel also has a great suggestion about how to transform such comments into code:
On the other side, Josef Strzibny is arguing that:
And the same idea is also supported by Philip Brown
Sebastien Auriault is sharing that concatenating strings with “«” is faster than other methods, especially with the improvement made by Jean Boussier:
Nate Hopkins talks about complexity:
The whole thread has a lot of learnings about what problems Rails tries to solve while also supporting the other alternatives:
“Having said all of this, I definitely think people should explore alternatives like Sinatra, Padrino, Roda, Hanami, etc... The Ruby community needs folks innovating outside of the Rails ecosystem. Striking the right balance is the tough part” - Nate Hopkins
Facundo Espinosa asked a question about which way to guard a before action people prefer:
If you go through the thread you will find great arguments for both cases. Here are two examples:
Stephan Kamper argues for the first example:
In my mind the action and the condition have a similar abstraction level which is better expressed in the 1st example. Also, the condition in this example seems to be more related to a business rule. In the second example the condition is expressed as 'a detail' of the action.
While spickermann argues for the second example:
I prefer the second version. Keeps the callback section in the class clean and easier to scan. And makes the condition part of the method and therefore makes the method more resilient against misusage and its preconditions easier to understand for future readers.
Dino shared a performance tip for Rails about listing all models fields when doing a select and using accessed_fields method for getting the used ones:
Articles and Videos
Rails Conf 2022 videos are up on Youtube.
Kevin Murphy wrote about testing response code for 4xx and 5xx.
Yaroslav Shmarov shared a new tutorial about using StimulusJS to select all checkboxes.
Carlos shared an excellent article about How to contribute to Ruby on Rails
RUBYLAND shared an article about creating a static website with Middleman and deploying it to AWS.
Joe Masilotti shared an article (actually a great collection of articles) he wrote about Hybrid iOS apps with Turbo. The whole thread explains how to build this kind of app.
Greg Molnar shared the latest issue of This Week in Rails with the newest changes in Rails.
Phoebus shared an interview he did with Josef Strzibny about Josef's indie hacking journey. See video on Youtube
Matthew Alp shared an article he wrote about fast method lookup and execution in Ruby.
Two new podcasts episodes are out this week: Build an Admin for Your Rails App Easily with Avo and Remote Ruby with Konnor Rogers (maybe more, but I did not yet have time to discover them).
New libraries or updates
Marco Roth published a new gem https://github.com/marcoroth/turbo-morph which is a morphdom integration for Turbo Streams.
Read this thread to see some use cases for this gem:
David Copeland published https://github.com/sustainable-rails/confidence-check that works with both RSpec and Minitest. Here is what the author says about this gem:
Sometimes tests have some setup required before you run the test, and sometimes that setup is complicated, and sometimes that setup can break if other parts of the system aren't working. When that happens, you can have a test failure that doesn't mean your code is broken, just that some other code is broken.
You should read this thread where he explains what does confidence-check achieve, and here is what it looks like with Minitest:
Jim Gay released a new gem called expand to make creating modules/classes under the existing namespace easier.
Here is how it looks like:
Thank you for reading this.
If you like it and have suggestions of people working with Ruby and sharing interesting stuff, you can find me on Twitter @lucianghinda
Thanks for reading Short Ruby Learnings! Subscribe for free to receive new posts and support my work.