Short Ruby Newsletter

Share this post

šŸ¤ Short Ruby - edition #17

newsletter.shortruby.com

šŸ¤ Short Ruby - edition #17

Briefly about everything happening in Ruby world

Lucian Ghinda
Nov 7, 2022
2
2
Share this post

šŸ¤ Short Ruby - edition #17

newsletter.shortruby.com

If you want a short excerpt of this newsletter, I created oneĀ here

This edition was created with support fromĀ @adrianthedevĀ fromĀ Avo for Ruby on Rails (a friendly full-featured Rails admin panel), @jcsrb, and @kpumuk, who sent me recommendations to include in the newsletter.


about the community

Linus Torvalds talks about Git's success in an interview:

Source: Linus Torvalds talking about Git success in Pat Gelsinger and Linus Torvalds talk Linux, open source, technology and more

I listened to the interview, and I want to make this clear: What Linus is saying is that Git reached success quicker than he expected, thanks to Ruby developers. In this context, ā€œstrangeā€ is used somehow, like saying strange people that understood what I created.

Collin JilbertĀ shared lovely words celebrating his 4th year of writing code:

Source: Collin Jilbert on Twitter

šŸ‘‰Ā Kirill ShevchenkoĀ sharedĀ in a thread multiple examples of using Ruby predefined global variables:

uby has many pre-defined global variables. There are 5 of them you might find useful: $!, $$, $0, $@, $* $! contains the last raised exception in the current call stack.
Source: @kirill_shevch onĀ Twitter

Here is a summary of the code samples shared by Kirill in the thread:

You should read the thread as more people shared how they use these variables. Also, if you are curious about what global variables Ruby has, check out the documentation about Pre-defined global variables.

If you don’t want to work with the $ notation, there is a module (now part of stdlib) called ā€œEnglishā€ (seems to be since Ruby 3.0):

Source: https://docs.ruby-lang.org/en/3.1/English.html

šŸ‘‰Ā Adrian MarinĀ shared a thread about how to move from Heroku to Dokku:

Today I moved Avo's demo apps from Heroku to a @dokku instance. Here's what I did šŸ§µšŸ‘‡
Source: @adrianthedev onĀ Twitter

šŸ‘‰Ā David CopelandĀ shared a thread where they build a good DX for running bin/setup:

Source: @davetron5000 on Twitter

You can find the scripts for doing this setup on Dave Github. It is worth considering this brief summary of what makes a good bin/setup script:

bin/setup needs to have a few properties:  • does the setup • is idempotent/safe to run any time • is clear what it's doing & where things go wrong • handles and reports useful errors • relis only on stdlib not gems because it installs them! 3/
Source: @davetron5000 on Twitter

šŸ‘‰Ā David TerenĀ shared a code sample showing how to configure Rails 7 (Hotwire) and Devise logout:

A simple solution for Rails 7 (Hotwire) & Devise sessions destroy.
Source: @davidteren onĀ Twitter, see the code here

šŸ‘‰Ā Aaron PattersonĀ sharedĀ  a PR that was merged to Ruby about changing how Classes and Module are storing instance variables:

Today @jhawthorn merged a PR that changes Classes and Modules to use object shapes for storing instance variables rather than a hash table. Class IVAR reads are 2x faster, and it saved 16MB RAM! šŸ‘
Source: @tenderlove onĀ Twitter

šŸ‘‰Ā Greg NavisĀ shared a thread explaining some Active Record methods that can be useful when dealing with persistence:

šŸ’” Rails tip: Active Record implements a bunch of predicate methods that can come in handy at times 1ļøāƒ£ previously_new_record? 2ļøāƒ£ previously_persisted? 3ļøāƒ£ destroyed? 4ļøāƒ£ new_record? 5ļøāƒ£ persisted? ā¬‡ļø Let's have a look at each one of them.
Source: @gregnavis onĀ Twitter

If any of these methods are interesting, you should read the entire thread, as it has code samples for each method. Here is a summary of them:

  • previously_new_record? → ā€œReturns true if this object was just created – that is, prior to the last save, the object didn't exist in the database and new_record? would have returned trueā€

  • previously_persisted? → ā€œReturns true if this object was previously persisted but now it has been deletedā€

  • destroyed? → ā€œReturns true if this object has been destroyed, otherwise returns false.ā€

  • new_record? → ā€œReturns true if this object hasn't been saved yet – that is, a record for the object doesn't exist in the database yet; otherwise, returns falseā€

  • persisted? → ā€œIndicates if the model is persisted. Default isĀ false.ā€

šŸ‘‰Ā Kevin NewtonĀ shared a code sample on Github showing how to evolve the code when using pattern matching and decide what to execute based on object type:

I keep seeing places in Ruby where I want the pattern for an object to be defined on the object itself, and not in the callsite where it's being matched. Maybe I should just be overriding the === operator.
Source: @kddnewton onĀ Twitter

Here is a small sample of the code there, but you should read the entire code as Kevin wrote there a good story about how the code evolved:

šŸ‘‰Ā Benoit DalozeĀ warned about the grpc Ruby gem:

If you are thinking about using the grpc Ruby gem, think twice about it. It's currently basically unmaintained. Here are two important PRs ready to be merged but waiting for months: https://t.co/GVlUGipX0C https://t.co/1qhG03c82E even though many people are waiting the 2nd fix.
Source: @eregontp onĀ Twitter

Aaron Patterson proposed a solution to use the grpc_kit from Cookpad

šŸ‘‰Ā Dima FatkoĀ sharedĀ a new gem sidekiq-iteration that makes long-running Sidekiq jobs interruptible and resumable:

Introducing sidekiq-iteration (https://t.co/ir7cKKErUK) a new gem that helps to make your long-running sidekiq jobs interruptible and resumable by design. For those familiar with job-iteration from Shopify, this is an adoption of that gem to work with raw Sidekiq (no ActiveJob). https://t.co/1GVza2iYBV
Source: @fatkodima onĀ Twitter

šŸ‘‰Ā Celso De SaĀ sharedĀ that the Junior Developer Program at Sierra Rails is open:

2022-11-02 17:51:57 UTC Hey #Ruby Juniors! @dpaola2 is about to open up the next batch of @SierraRails Junior Developer Program. You can apply here:
Source: @CelsoDeSa onĀ Twitter

šŸ‘‰Ā Ryan BatesĀ sharedĀ asked a question about changing directory structure in Rails:

Has anyone tried changing their Rails app directory structure to vertical slices (feature based) instead of horizontal layers? Any success?
Source: @rbates onĀ Twitter

Among the answers:

  • This good article by Jason Sweet about Organising Rails files by meaning

  • A video from RailsConf 2022 about Laying the Cultural and Technical Foundation for Big Rails by Alex Evanczuk

  • This episode from Code With Jason podcast 162 - Large Rails Apps with Alex Evanczuk, Software Engineer at Gusto

  • Using engines helps with isolating boundaries but has the cons of adding friction to the development process

This suggestion about how to organize could also be worth considering:

Conversation on Twitter

šŸ‘‰Ā Jared WhiteĀ shared that the Rails readme already specifies where to put the business logic:

Every time I hear of a discussion of ā€œwhere do I put my business logic in my Rails appā€ I wonder why we even need to discuss this. šŸ˜… The answer is right in the Rails readme! Like, right there! In clear and unambiguous terms!
Source: @jaredcwhite onĀ Twitter

Here is the relevant quote from Rails docs:

Source: rails/rails README.md on Github

A brief version of this is also present in the official Ruby on Rails guide:

Source: guides.rubyonrails.org

I suggest you read the entire conversation related to Jared's share. It has some great points about how to organize code and also a good debate about naming.

šŸ‘‰Ā Joel DrapperĀ shared about the future of Phlex and supporting multi-format:

Phlex is going multi-format with dedicated builders for HTML, RSS, ATOM, SVG and JSON. They’ll all use the same basic format — a Ruby class with a template method and optional initialiser — and they’ll all benefit from boot-time compilation.
Source: @joeldrapper onĀ Twitter

šŸ‘‰Ā Greg NavisĀ shared a thread about how Active Record id attribute works:

1ļøāƒ£ Active Record implements primary key handling in a dedicated module: github.com/rails/rails/bl…  It's clear the id method reads from the column stored in the primary_key attribute.  This conversion happens in other places, too.
Source: @gregnavis onĀ Twitter

šŸ‘‰ CJ Avilla shared about the source of using underscores:

I've always wondered where that convention came from. We see it in Ruby with __FILE__, in python its everywhere and how you override methods on objects __str__, but where did this start?
Source: @cjav_dev on Twitter

šŸ‘‰Ā AkshayĀ shared about self keyword in Ruby:

Ruby's self keyword can be pretty confusing to understand, especially if you're new to Ruby. Not understanding it often leads to subtle bugs that can be difficult to debug. Here're the different forms it can take, depending on the context in which it's used šŸ‘‡
Source: @ak_rails onĀ Twitter

And here, Akshay shared a very good summary:

Here are four rules to keep in mind:  • Only one object can be `self` at a given time • `self` is constantly changing as a program executes • When you call a method, the receiver of that method becomes `self` • All methods without an explicit receiver are called on `self`
Source: @ak_rails on Twitter

šŸ‘‰Ā Kirill ShevchenkoĀ shared a code sample showing how to store cache and session in Redis using redis-rails gem

By default, Rails stores cache into memory in the same process and Session into encrypted cookies, but you can store both in Redis. For cache, Rails has a built-in configuration, and for session configuration, you can use, for example, the "redis-rails" gem
Source: @kirill_shevch onĀ Twitter

šŸ‘‰Ā Greg NavisĀ shared a thread about how Active Record queries are cached in controller actions. I invite you to read the entire thread where he explores how this works, and it shows code samples from Rails handling the cache:

2022-11-04 12:00:09 UTC šŸ’” Rails tip: Active Record queries are automatically cached in all controller actions Result: running the same query again while handling a request will NOT hit the database. āš ļøThis does NOT imply "run queries willy-nilly"āš ļø But there's more ...
Source: @gregnavis onĀ Twitter

šŸ‘‰Ā Matt Swanson shared Ruby English-friendly alternatives to gsub and chomp:

Programmers coming from other ecosystems are often shocked at much Ruby looks like pseudocode. Instead of using methods like `gsub` or `chomp`, you can write super readable alternatives with `delete_prefix` and `delete_suffix`
Source: @_swanson onĀ Twitter

šŸ‘‰Ā Josh CheekĀ shared a code sample about various forms of ā€œclass methodā€:

Example of why I find "class method" a dubious term:
Source: @josh_cheek onĀ Twitter

Joel Drapper shared a short explanation:

Source: @joeldrapper on Twitter

šŸ‘‰Ā Greg NavisĀ shared a tip about how to run two branches in the same time with git worktree

Let's rehash the steps:  1ļøāƒ£ Create a worktree 2ļøāƒ£ Go to the worktree directory 3ļøāƒ£ Checkout the branch 4ļøāƒ£ Start Rails on a different port
Source: @gregnavis onĀ Twitter

šŸ‘‰ Jim Gay shared a code sample about how to define a method that should be implemented in subclasses:


If you have read so far and you like the content, maybe you take into consideration sharing this and subscribing:


Related (but not Ruby-specific)

šŸ‘Œ Jason SwettĀ shared advice about not making premature generalization:

Programming tip: Don't prematurely generalize. The logic is the same for that of premature optimization: when you try to solve the problems of tomorrow today, your efforts will often turn out to have been a waste.
Source: @JasonSwett onĀ Twitter

He also asked about why duplication is more acceptable in test code than in application code:

It's often said that duplication is more acceptable in test code than application code. Why? (I have my own answer but I want to hear what others have to say.)
Source: @JasonSwett onĀ Twitter

šŸ‘ŒĀ Chris Mc CordĀ shared a quote from the creator of VueJS Evan You:

It's pretty wild watching the pendulum swing back to server side rendering: "Not only is it the default, the Next documentation also recommends users to stay in server mode as much as possible to improve end-user performance.ā€ via @youyuxi
Source: @chris_mccord onĀ Twitter

šŸ‘Œ Tobias Petry.SqlĀ shared an SQL tip about how to place NULL values at the start or end of a query:L

āš”ļø Database Tip Sorting on nullable columns is nerve-stretching: They most probably will not be placed in your desired order. However, you can simply change the placement of NULL values to be at the start/end depending on your requirements.
Source: @tobias_petry onĀ Twitter

šŸ‘Œ Joel DrapperĀ shared about the problem with sustaining independent open-source projects:

Here’s a thing that’s sad: the only viable way to fund an independent open-source project is to use it to promote paid closed-source courses and ebooks. You can’t give those things away for free because engineers can’t expense sponsorships on their personal development budgets.
Source: @joeldrapper onĀ Twitter

Lucian Ghinda also shared an idea about how to support open source:

An idea for tech companies:   Please allow your employees to spend the development budget on sponsoring open-source software.  The people doing open-source work or creating things for the dev community are creating knowledge!
Source: @lucianghinda on Twitter

šŸ‘Œ Ā Dave PaolaĀ sharedĀ a good thread about onboarding juniors:

Just had a conversation with a junior developer that highlights so many of the issues many companies face. The issues were numerous but there is one that outshines the others: lack of great onboarding.
Source: @dpaola2 onĀ Twitter

If you are interested in this subject, go ahead and read the entire thread and also you might want to check out these two articles from PlanetArgon:

  • How We Onboard New Software Engineer Hires with Eddy

  • How to Successfully Onboard a Junior Developer


Articles and Videos

Something to read

Newsletters

šŸ—žļø Women On RailsĀ sharedĀ a new edition āœ‹ Newsletter #38: Me Too

šŸ—žļø Greg Molnar shared a new edition of This Week in Rails: An improved error page, šŸ—žļø groundwork for composite primary keys and Stimulus 3.1.1

šŸ—žļø Ruby Weekly published a new edition 627: Sidekiq 7.0 – it's now embeddable

šŸ—žļø Ruby LibHunt published a new edition of the Awesome Ruby Newsletter

šŸ—ž Andrew Mason shared a new edition of Ruby Radar 75 - Happy November

āœšŸ¾ Articles

Xavier NoriaĀ published a new articleĀ A Pattern for STIs in Rails

Eric Berry sharedĀ an article written by Joe Wilm (OneSignal CTO) about Lessons Learned From 5 Years of Scaling PostgreSQL

Eric BerryĀ sharedĀ an article written by Pasha Gray about Effective Queries with Rails and PostgreSQL

Something to watch šŸŽ„ or listen šŸŽ§

Videos

šŸŽ„Ā Nate BerkopecĀ shared their talk at Kaigi on Rails is now on Youtube:Ā All About Queueing In Rails Applications

šŸŽ„ Joel DrapperĀ sharedĀ a new pairing session with Kasper Timm Hansen about Mixing HTML attributes in Ruby

šŸŽ„Ā Joel DrapperĀ shared a new episode where he paired with Chris: Coding with Chris - Goblin Grinder part 2

šŸŽ„Ā Tom StuartĀ published a new video Making a WebAssembly interpreter in Ruby, part 14

šŸŽ„Ā Drifting RubyĀ shared the video walkthrough forĀ This Week in Rails - Nov 4th, 2022

šŸŽ„ Stan Lo shared their video from RubyKaigi ruby/debug - The best investment for your productivity

Audio & Podcasts

šŸŽ§ Drew BraggĀ published a new episode with Noel Rappin where they discussed the new Pickaxe book for Ruby 3.2: Episode 11 - Noel Rappin

šŸŽ§ Matt SwansonĀ published the first episode of the new podcast called YAGNI (You Ain't Gonna Need It). The episode is with Chris Toomey, and it is about Detailed commit messages

šŸŽ§ The Ruby on Rails PodcastĀ published a new episode with Dave Paola Sierra Rails (The Apprenticeship Pattern)

šŸŽ§ Andrew MasonĀ shared a new episode of Remote Ruby with Kevin Newton about Ruby Parser, SyntaxTree, Prettier Ruby and a sneak peek

šŸŽ§ Ruby for All published a new episode Updating The PickAxe Book with Noel Rappin

šŸŽ§ The Bike Shed published a new episode 360: ActiveRecord Models

Gems, Libraries, and Updates

🧰 Xavier Noria shared a new release of Zeitwerk 2.6.2. Check the changelog and be mindful not to use any private interface. Xavier is planning to protect the private interfaces:

This release starts a series of gradual patches in which private interface is enforced with stricter formal visibility. (source: https://github.com/fxn/zeitwerk)

🧰 Marco Roth shared that Stimulus released a new version v3.1.1. Read the changelog

🧰 Andrew Culver published a new gem bullet_train-routes. Read the changelog. Here is what it looks like:

Terri OĀ sharedĀ a tool to check for vulnerable openssl cve-bin-tool:

For anyone handling "I want a list of every thing we have that uses openssl" today: https://t.co/V11E07iVe9​ cve-bin-tool --runs openssl <directory> To check just for vulnerable openssl, or cve-bin-tool <directory> To see if you have any other "fun" surprises. #infosec
Source: @terriko onĀ Twitter

🧰 Stefanni Brasil shared that they released faker-ruby/faker v3.0.0

🧰 Nate Hopkins published a new version of TurboReflex v.0.0.13

🧰 Takashi Kokubun shared they merged a new PR to irb about Allow non-identifier aliases like Pry's @ and $

🧰 Mike Perham shared that Sidekiq OSS, Pro and Enterprise v.7.0.1 are released. Read the changelog


Thanks for reading Short Ruby Newsletter! If you enjoyed this and want to receive the newsletter weekly in your inbox, consider subscribing:

2
Share this post

šŸ¤ Short Ruby - edition #17

newsletter.shortruby.com
Previous
Next
2 Comments
Steven Rosenberg
Nov 8, 2022Liked by Lucian Ghinda

Great newsletter!!

Expand full comment
Reply
1 reply by Lucian Ghinda
1 more comment…
TopNewCommunity

No posts

Ready for more?

Ā© 2023 Lucian Ghinda
Privacy āˆ™ Terms āˆ™ Collection notice
Start WritingGet the app
SubstackĀ is the home for great writing