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:
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.
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.
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.
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.
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:
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
If you go through the thread you will find great arguments for both cases. Here are two examples:
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.
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.
Articles and Videos
Rails Conf 2022 videos are up on Youtube.
RUBYLAND shared an article about creating a static website with Middleman and deploying it to AWS.
New libraries or updates
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:
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.