👋 Short Ruby - edition #16

Briefly about everything happening in Ruby world

If you want a short excerpt of this newsletter containing only some of the images with code, I created one here. But I invite you to read the entire newsletter as it has excellent content 😊.

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.

👉 Justin Searls shared about the productivity gain from using Turbo and Stimulus:

 have been SO PRODUCTIVE since getting up to speed on Turbo and Stimulus (plus tailwind) in Rails 7 that I'm at serious risk of writing a "You Might Not Need React" post. Hold me back!

👉 Greg Navis shared a Rails tip about how to test view logic in vanilla Rails:

2022-10-24 13:08:11 UTC 💡Rails tip: view logic can be easily tested in vanilla Rails 1️⃣Create a directory test/views 2️⃣I suggested following the same grouping as in app/views, e.g. app/views/shared➡️test/views/shared 3️⃣Create test classes inheriting from ActionView::TestCase There are risks though ⬇️

👉 Vinicius Stock shared that the YJIT in Ruby 3.2 will provide performance improvements for Ruby LSP:

Starting with Ruby 3.2, YJIT provides significant performance improvements to the Ruby LSP and makes the experience in the editor much smoother

If you want to try Ruby LSP there is a VSCode extension: ruby-lsp. In case you want to use it with other editors Vinicius shared it should work with any editor supporting LSP spec:

The Ruby LSP should be able to connect to any editor that supports the LSP spec. To use it with YJIT, you need to configure your editor to start the server with it. This depends on the editor, but something like RUBYOPT=--yjit bundle exec ruby-lsp

👉 Fable shared that Stripe Ruby codebase is now formatted using their Rubyfmt

100% of Stripe's Ruby codebase, which is the largest single Ruby codebase in the world, is now autoformatted with Rubyfmt. We'll be upstreaming the changes we made soon. I'm very excited.

For context:

Today Sorbet runs over Stripe’s entire Ruby codebase, currently amounting to over 15 million lines of code spread across 150,000 files

(source Sorbet: Stripe’s type checker for Ruby)

👉 Nate Matykiewicz shared a piece of code to put on test.rb environment to do logging when running tests only when an environment variable is set:

if ENV['TEST_LOGGING'] config.log_level = :debug else puts 'Logs are being suppressed to speed up the test suite. ' \ 'Set TEST_LOGGING=1 to add logging back.' config.log_level = :warn end

👉 Kirill Shevchenko shared that Ruby also has fail as an alias for raise:

TIL: Ruby has an alias for the raise keyword - fail. Luckily, it's covered in a rubocop.

In case you are wondering when to use fail or raise, Zalom shared what Rubocop style guide is recommending:

Use `fail` to signal exceptions (not catching them)

Use `raise` to rethrow exceptions (catch them)

I recommend reading the discussion on Rubocop about raise and fail and read the article Jim Weirich on Exceptions on avdi.codes blog:

👉 Janko Marohnić shared a piece of code about setting up password pepper in Rodauth:

🔒A password pepper is a secret that prevents an attacker who obtained password hashes from bruteforcing them. If you’re using bcrypt, note that it truncates passwords longer than 72 bytes, so makes sure to limit the password’s bytesize. Here is how you’d set it up in Rodauth:

👉 Joel Drapper shared a code sample of original code and code generated by Phlex compiler:

Original Phlex view on the left. On the right is the compiled patch to eval with the correct lexical scoping. We don’t do anything special with attributes at the moment otherwise this whole template would be one string. However, you can see tags are compressed when possible.

👉 Andrzej Krzywda shared a thread about how to split Rails architecture between app layer and domain layer:

The missing Ruby on Rails architecture 🧵let me explain the 10 rules here

👉 Matt Swanson shared a code sample showing how to use tally:

🧮 Ruby's Enumerable#tally is so underused It's great for quickly exploring your data without writing a bunch of loops and counters

👉 Noel Rappin shared that the new book he is working on Programming Ruby 3.2 is available in beta:

Noel shared an entire thread about what’s in the book, here is a preview:

What's new? Very broadly speaking, changes in this book fall into one of a few different categories: * New language features * New tools * Different external environment * Usage patterns of existing tools /4

You can buy the book here at The Pragmatic Bookshelf.

👉 Nishiki Liu asked for resources about learning to program lower level in Ruby:

I’m really interested in getting into slightly lower level stuff with Ruby. Threading, Puma, etc. Does anyone have any recs on where to start?

Here are the recommended resources/paths:

👉 Richard Schneeman asked a question about alternatives to default_scope:

What are your favorite alternatives to default_scope in Rails?

Here are two concrete answers to this question:

  • "Named scopes and services" - @BijanRahnema 

  • "create little methods (or something service objects) that wrap up more explicit scopes into something easier to wrangle" - @ektastrophe

It is also worth reading the discussion between David Cooperland and Richard Schneeman about onboarding new developers. Here is one of the things worth considering when onboarding new developers:

OK, fair, I did not answer your question :) Everywhere I have worked and done onboarding, it ALWAYS included an overview of the data model + docs. Message is “data model is super important to understand, you can’t learn it in one day, but there are docs” + code review

👉 Brandon Weaver asked about how to break up large models:

Any Ruby/Rails folks have particularly favorite resources for breaking up very large models? I might do some writing on this myself later.

Here are some recommendations:

👉 Adrian Marin published a new gem called class_variants:

If you're using Tailwind CSS and you find it difficult to manage the classes for your component's variants, I made a gem that could help you. `class_variants` allows you to configure and apply classes for components based on variants.

👉 Kirill Shevchenko shared a code sample about __method__ and __callee__:

You can get the name of the called method with __callee__ and __method__ of the Kernel module. __method__ returns defined name. __callee__ returns called name. The difference can be easily illustrated with an alias:

👉 Kateinoigakukun shared a code sample showing a minified code:

An experimental Ruby minifier showed 15% size reduction. (22MB -> 18MB) Very simple but big win😜

👉 Kirill Shevchenko shared a code sample showing how to run Rails and Sidekiq in the same process:

Now you can run Rails and Sidekiq with simple "rails s" command in the same process. 1. Upgrade to Sidekiq 7 2. Add settings to the Puma config:

👉 Pascal Laliberté announced the release of their new project supercharts.dev:

Launch💥 https://t.co/AfDX6B1hjY, a plugin to scaffold a chart into a @bullettrainco Rails app Perfect if: - you're building a new project that needs charts - you're already on Bullet Train for your app or considering it - you're too swamped to learn the "chart part"

👉 Chris Oliver asked about pain points when building Rails apps:

What's frustrating or hard about building Rails apps that shouldn't be?

Here are some of the answers, but I suggest you read the entire conversation:

  • “Lack of passwordless solution: OmniAuth integrations, WebAuthN, Passkey and magic link bundled together” (@bradgessler)

  • "Simple" refactoring: like renaming classes/models and finding all associated references, moving classes into modules, renaming (instance) variables." (@marcoroth_)

  • "Rails is still painful to deploy compared with JS frameworks." (@madebyivor)

  • "Seamless editor support with type hints" (@strzibnyj)

  • "There’s way too much boilerplate for controllers, views, and partials. It makes it really difficult to build a basic CRUD app, esp as they become larger and more complex. It also makes it hard to plug external engines into Rails that ship with views." (@bradgessler)

  • "I think you should be able to disable the asset pipeline with a flag (besides the config)" (@thdaraujo)

  • "Scaling (but not infra, rather code / team)" (@katafrakt_pl)

  • "I wish I had an easy way to force myself to apply a specific scope. It should be the opposite of default_scope" (@dpaluy)

  • "upgrades .. lately I managed to upgrade a rails app from version 4 to 5.0 .. then went into gems compatibility issues." (@jobas6a)

  • "Configuring different environments. Setting up a pipeline etc." (@MyBuddyAndrew)

  • "Identify slow boot cause in larger apps as well as refresh slowdowns in development mode" (@adrienpoly)

  • "Rails is now built for existing rails developers. I feel it’s lost the ‘beginner friendliness’ it used to have. I tried to start rails dev again about 12 months ago and it was just too hard to piece it all together." (@LumSmith)

  • "The asset pipeline. So many damn problems with it. Even just adding an image to your site can break a deploy." (@fuzzygroup)

  • "Complex dynamic forms" (@jdisselhoff)

  • "Make it works on windows" (@Hihihihiu1)

  • "There's no business logic layer between controllers and models that lets you share code. So as your code base scales in size, there's a struggle to maintain things in a Rails-y way versus maintaining good conventions." (@danielrhodes)

  • "Testing story for Turbo / Hotwire is just “Capybara” - there should be a less brittle way to test those use cases." (@stephenprater)

👉 Greg Navis shared a Rails tip about using prepend_view_path:

💡Rails tip: if you're redesigning your views then prepend_view_path may be very helpful. Pros: 1️⃣ Step-by-step conversion 2️⃣ Fallback to an old view if a new view is absent 3️⃣ Minimal controller changes

👉 Eric Berry shared a thread about why RubyMine is a great IDE:

Yesterday during a pair session, I heard “I can’t believe how much your editor does for you!” I agree with her! What’s the secret? @rubymine It’s worth spending the time to learn this amazing IDE. Here are some reasons why I love it:
1. CMD+Click any class/method to go direct to source (including gems) 2. Super smart auto-correction and suggestions 3. Integrated super powerful SQL tooling (inc. explain + diagrams) 4. Git client (I do all commits) 5. Well supported plugin ecosystem

👉 Marco Roth shared they created a new gem called phlexing that can help with converting from ViewComponent to Phlex:

n order to help other people build tools for and around Phlex I extracted the converter which powers https://t.co/5fqGw8sbPZ into it's own separate gem. With that people can programmatically convert ERB to Phlex from within Ruby. The gem is available on Rubygems as `phlexing`

 Heroku has a new offering that might work for some folks @ $13/mo. - $5/mo multiple dynos (1k compute hrs) - $5/mo postgres (up to 10k rows) - $3/mo redis (25mb) Not perfect but most of the alternatives I've seen people talk about cost the same or more.

Mastodon accounts

Here are some accounts from Ruby community that you can find on Mastodon (left Twitter → right Mastodon):

Probably there are many more people now on Mastodon. Here is the public timeline for ruby.social or you can read the ruby tag or rails tag to see what people are sharing.

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)

🧐 Brandon Weaver shared some developer salary data in SF and other major metros:

@tdesseyn SF and other major metros can see bases around: Entry: 120k Mid: 150k Senior: 190k Staff: 230k Principal: 270k Above: 300k+ Less general, but potentially good to know.

🧐 He also shared some data about equity:

🧐  Julia Evans shared a nice drawing about writing tests when debugging:

debugging strategy: do the annoying thing

🧐 Cezar Halmagean shared a thread about why learning to sell and market your skills as a developer are as important as learning to code:

Don't stop at coding. Back when I started learning how to code, I thought the single most important thing is to become great at writing code. But a decade later, I realized that's just the beginning. Learning to sell and market your skills is way more important. Here's why 👇

Here is an excellent way to think about how to position yourself, but you should read the entire thread as it has nice ideas:

3/ You'll make recruiters and HR irrelevant Like it or not, coding is a commodity. That's why you see it sold at $20/h. By positioning yourself as an investment (providing business solutions) not an employee, you've removed yourself from the game that everyone else is playing.

🧐 Nate Berkopec shared a quick tip to enable hash joins in Aurora MySQL:

It kind of blows my mind how often you can find critical performance features that literally just need to be turned on. Who knew that Aurora MySQL has hash joins, but you have to turn them on first?

🧐 Michael Feathers shared about how to choose what to test:

Write tests where you want your module boundaries to be. Writing them any other place just shifts the boundary — and your modularization.

🧐 Gregory Szorc shared a new feature in Git 2.38

Git 2.38 added a `git rebase --update-refs` argument that automatically moves branches associated with rewritten non-head commits. You can now stack multiple branches in the same commit series and rebase without losing your mind. Big UX win!

How to rebase stacked Git branches is a good article that goes to explain more about this feature and shows how to use it.

Articles and Videos

Courses/Books/Events

Joe Masilotti shared the new workshop they are launching the “Turbo Native workshop.” The tentative date is Thursday, December 15. Register here

Something to read

🗞 Newsletters

Joe Masilotti published a new edition of the Hotwire Dev Newsletter: October 2022 edition

🗞 Ruby Weekly shared a new edition 626 - The state of YJIT

🗞 Ruby LibHunt published a new edition of the Awesome Ruby Newsletter

✍🏾 Articles

Joel Drapper shared an article they wrote about Custom exception inheritance

Niklas Stephenson shared an article they published about how to use ShapeUp to empower the team: Empowered ShapeUp

David Copeland shared an article they wrote about How I Use Tachyons for CSS

Something to watch 🎥 or listen 🎧

🎥 Videos

🎥 Takashi Kokubun shared their talk at RubyKaigi about Ruby 4 JIT

🎥 The Rubber Duck Dev Show also published the second episode of Coding with Chris - Goblin Grinder Part 1

🎧 Audio & Podcasts

🧰 Gems, Libraries, and Updates

🧰 Hanami announced Hanami v.2.0.0.beta4 the last version before the final release. Read the article that describes the changes at Hanamirb.org

🧰 Avo published a new release of Avo Rails Admin. Read the release notes here or watch the video showing the main new features here. They also ask for feedback and ideas.

🧰 Chris Oliver announced a new version for prefixed_ids gem:

🧰 Josef Strzibny shared a new option for lightweight search: Sonic, written in Rust but with sonic-ruby gem for Ruby.

🧰 Mike Perham shared a new testing library: Maxitest = Minitest + all the features you always wanted:

🧰 Mike Perham announced the release of Sidekiq 7.0. Read about what’s new in Introducing Sidekiq 7.0 | Mike Perham, Sidekiq 7.0: Metrics and Sidekiq 7.0: Embedding

🧰 Rob Zolkos shared a gem they discovered about compressing JS: Terser

🧰 Kevin Newton shared a gem named actionview_precompiler: “This optimization aims to improve cold render times and to allow more memory to be shared via CoW on forking web servers.”

🧰 Julian Rubisch shared a gem that helps build onboarding flows in Rails app. Check out the abraham gem.

🧰 Lázaro Nixon shared they are working on a PR for Rails to introduce where.present and 2. See the Pull Request #46343

Reply

or to participate.