Short Ruby Newsletter

Share this post

Issue #2 - 18 - 24 July 2022

newsletter.shortruby.com

Issue #2 - 18 - 24 July 2022

Lucian Ghinda
Jul 25, 2022
3
Share this post

Issue #2 - 18 - 24 July 2022

newsletter.shortruby.com

Hello,

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:

Source: @fxn on Twitter

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:

Source: @davetron5000 on Twitter

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.

Source: @andycroll on Twitter

Alexandre Ruban explained how to use ActiveSupport::Deprecation.warn when changing the public API of a an object:

Source: @alexandre_ruban on Twitter

(not Ruby but more web related) Dave Thomas shared a TIL about drawing a vertical bar using flex:

Source: @pragdave on Twitter

Jean Boussier shared that he did an improvement in Ruby and increased the performance of `String#«` with 30%:

Source: @_byroot on Twitter

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.

Source: @siaw23 on Twitter

Steve Polito shared an example of Rails helpers for working with date and time:

class User < ApplicationRecord 	def is_minor? 		18.years.ago.before?(birthdate) 	end end  minor = User.create(birthdate: Date.current - (18.years - 1.day)) adult = User.create(birthdate: Date.current - 18.years)  minor.is_minor? # => true  adult.is_minor? # => false
Source: @stevepolitodsgn on Twitter

Cezar Halmagean shared a tweet with advice about not using comments when writing Ruby code.

Source: @chalmageam on Twitter

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:

Source: @joeldrapper on Twitter

Joel also has a great suggestion about how to transform such comments into code:

Source: @joeldrapper on Twitter

On the other side, Josef Strzibny is arguing that:

Source @strzibnyj on Twitter

And the same idea is also supported by Philip Brown

Source: @philipbrown on Twitter

Sebastien Auriault is sharing that concatenating strings with “«” is faster than other methods, especially with the improvement made by Jean Boussier:

Source: @websebdev on Twitter

Nate Hopkins talks about complexity:

Source: @hopsoft on Twitter

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:

Source: @faqndoE97 on Twitter

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:

Source: @dixpac on Twitter

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

Turbo Morph

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:

Twitter avatar for @marcoroth_
Marco Roth @marcoroth_
Have you ever heard of `morphdom` and can't quite imagine why and how it might be useful in your server-rendered web-applications? Here are some use-cases where you would want to use the new `morph` action 🧵
Twitter avatar for @marcoroth_
Marco Roth @marcoroth_
I just wrapped up and published a simple morphdom wrapper for the new Custom Turbo Streams Action that shipped with Turbo 7.2.0-beta.1 🚀 https://t.co/ELvX3jX3k4
5:59 AM ∙ Jul 19, 2022
26Likes12Retweets

Confidence Check

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:

Source: https://github.com/sustainable-rails/confidence-check by David Copeland

Expand

Jim Gay released a new gem called expand to make creating modules/classes under the existing namespace easier.

Here is how it looks like:

Source: https://github.com/saturnflyer/expand by Jim Gay

Outro

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.

Share this post

Issue #2 - 18 - 24 July 2022

newsletter.shortruby.com
Previous
Next
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Lucian Ghinda
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing