Image of Lucian Ghinda writing for notes.ghinda.com
Short posts mostly about Ruby and Ruby on Rails. You can find me at : Linkedin, Mastodon, Twitter, Bluesky or for longer posts at allaboutcoding.ghinda.com. Check goodenoughtesting.com if you want to learn to write fewer tests and cover more features. 
Subscribe via RSS here

You have to remain the driver and solution architect

I used Claude Code to refactor a series of tests from Minitest::Mock to the Mocha library this early morning. 

The main reason is that I had certain parts of the tests using Mocha and others utilizing Minitest::Mock. Since other projects I work on use RSpec, I find Mocha to be closer toons in RSpec, which minimizes the context change for me overall. 

I started with a simple example and provided this prompt: 

Go in the test/services/bluesky/save_thread_test.rb and redo the test 'empty result when client returns empty array' to use mocha instead of simple Minitest mock

Here is what Claude Code proposed as a change. It added the line with instance_variable_set (it is not marked here as a diff because I chose 'No' when it asked me to apply, and I'm not sure why it isn't marked).

What is true is that the SaveThread object is not handling dependency injection properly: it instantiates a Bluesky::Client, but it does not accept it during initialization.

Claude Code proposing to use instance_variable_set

So I followed up with: 

Instead of doing instance_variable_set wouldnt it be better to do depedency injection in the SaveThread object?

And I got the following answer:

Claude Code proposing to use class_eval to update the initializer

It’s an interesting solution, but I don't like it for obvious reasons: the object I want to test is also the object that is altered by the test (which goes against the fundamental principles of testing).


Thus, I asked: 

I prefer to change the SaveThread object itself

Notice that it included the client in the initializer, added an attr_reader for it, and also kept the previous memoized method.

Claude Code changes keeping the memoized method and the attr_reader

In my opinion, this type of behavior reinforces the notion that you need to know how you want your code to be structured (which I refer to as code design).

It also seems more important than ever to be able to read a diff and understand the proposed changes. LLMs may improve over time, but at least for now, it appears to me that to ensure good code quality, one must first have enough experience to recognize what good quality is and be able to determine which changes to accept or reject. 


Short Ruby Newsletter - edition 127

Short Ruby Newsletter - edition highlights

This edition was sponsored by Judoscale and was created with the help of Vladut Cosmin


🚀 Launches

  • Adam McCrea launched an exciting new tool for comparing hosting costs of web applications across multiple platforms → PaaS Pricing Calculator
  • Chetan Mittal launched a new book, Mastering Enums in Rails

📅 Events:

  • Kasper Timm Hansen announced a new workshop: Action View-Source Deep-Dive.
  • Ruby Central announced the early bird tickets will go on sale on Wednesday.
  • Euruko announced the opening of their Call for Proposals for EuRuKo 2025
  • Irina Nazarova announced the speakers for the SF Ruby Meet-up happening on 20 March

👉 All about Code and Ruby
There a lot of code samples included; here are just some of them: 

  • InfoSec reported critical vulnerabilities in the ruby-saml gem that allow attackers to bypass authentication, currently an update is available for this gem
  • Ruby on Rails announced a new release 8.0.2
  • Esparta shared his experience of bundle being interrupted during dependency installation while upgrading to Ruby 3.4.x
  • Matt Yoder shared a Ruby puzzle about string-freezing behavior.
  • Vladimir Dementyev showcased how easy it is to run Avo directly in the browser.
  • Peter Solnica shared his discovery that Ruby's byteslice method creates new string instances when operating on frozen, empty strings.
  • Graceful.Dev shared a trick about using filters and map together efficiently.
  • Michael Koper shared a security tip to prevent admin account password resets in Rails. You can discover up to 14 more concrete, ready-to-use code samples the community shares. 

Remember to read ️ 📐Thinking about Code, where Nate Berkopec shared advice on optimizing ActiveRecord database connections by using external poolers and a large pool setting, and Xavier Noria raised a question about Ruby's flat_map method, suggesting map_flat as a more intuitive alternative name. You can also discovere what Errol Schmidt shared their top 5 good and bad findings from Ruby on Rails app reviews based on production applications and many other interesting conversations. 

Inside 💡Around code section Donn Felker shared an interesting business opportunity as he is searching for a co-founder for one of his projects, Remi Mercier asked about questions that people have when starting to work with Minitest, Sourav shared his experience learning Ruby on Rails from a React/Next.js background, posting. 

🧰 Gems, Libraries, Tools and Updates 

  • Mike Perham released version 8 of Sidekiq gem
  • Carmine Paolino announced the release of a new gem RubyLLM. You can also follow the link to read the discussion on Hacker News about this gem (650 points and 165 comments)
  • Sean Gregory published a new gem Hokusai - A Ruby library for authoring GUI applications
  • Bruno announced a new gem Ruberto - A Ruby API wrapper for Uber
  • Brad Gessler announced a new gem superlink: A more powerful path and url generator for Rails
  • Tomasz Kowalewski published a gem memplify - Simplify memory profiling with memplify
  • Zach Morek published an interesting project  DOOM.rb - A Ruby implementation of the classic DOOM game engine, focusing on vanilla accuracy inspired by Chocolate DOOM

You will also find updates on their projects or libraries like Trix, activeagents.ai, Rubocop, Roda, Sitepress, standard, ruby-openai, Rubygems.


As always, we have more links to newsletters, videos, podcasts, and articles. 

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-127

About vibe coding

I am very close to putting this "vibe coding" phrase into ignore lists. But someone saying that Ruby is not fit for vibe coding made me look into what this term is.

Andrej Karpathy introduced this in a post on social media:

What is vibe coding - original definition

But it seems to have evolved into something that is now described more close to the following definition (source: Wikipedia)


> an inexperienced person describes a problem in a few sentences as a prompt to a large language model (LLM) tuned for coding.

Definition of Vibe coding from Wikipedia


Now let's take a look back at what Andrej wrote and try to add two contexts to this: 

  • He is an expert in LLMs - notice the term expert here
  • Let's focus a bit on some things I marked from his post
Annotated screenshot of the definition of Vibe Coding

Here are some questions I would like to ask myself: 

  • Look at 1️⃣ When he says I just work around it, how close is he to an amateur programmer or someone without any experience in coding? Could it be possible for things to look easy to work around because he has so much experience? 
  • Look at 2️⃣  When he says, "or I ask for random things," how random are those things, and how much of this know-how/experience is he asking for random things?
  • And now let's look at the last part, 3️⃣ - where he says, "I just <...> say stuff," and again, ask yourself when he says stuff to an LLM, how similar are his prompts/queries to a random person without any technical knowledge

This might be an expert blind spot for him and us, as we haven’t considered how much his expertise makes things seem simple. 

I am not saying this cannot happen, but seeing this vibe coding suddenly everywhere triggered my skepticism inside. 
It is just a thought; I am not saying this is not working or is not real. We might be in the beginning of something great. 

A possible advantage for Ruby for LLMs

An interesting point of view about the advantage #Ruby might have when considering AI

"generating equivalent functionality in Ruby costs approximately one-third of what it costs in TypeScript" (source)

Source: https://anykeyh.hashnode.dev/rubys-renaissance-in-the-ai-era

Support tech creators

I'm aware that as developers—or as tech enthusiasts—we're picky about subscribing to newsletters.

Here's the harsh reality:
1) Running a newsletter has some costs.
2) Advertisements are the primary means to cover newsletter costs.
3) A key metric for advertisers is the subscriber count.

There are other metrics involved, and also, for example, in the case of shortruby.com, many who chose to place an ad within it did so also to support the newsletter. Which is amazing, and I am so grateful to them.

I encourage you to subscribe to a newsletter if you enjoy it. 
The same applies to podcasts YouTube channels, or blogs. 

Support the creators when you can. RSS is also a good option; just be aware that it does not appear in the stats.

One great benefit of using Sorbet

One benefit of using Sorbet is that it can make VSCode and Neovim almost on par with RubyMine's excellent behavior of being able to go to definitions and references from almost anywhere to anywhere. It helps so much with debugging and refactoring. 

And that is amazing in a dynamically typed language. 

Trying claude code for the first time with Ruby on Rails

This morning I played a bit with Claude Code and tried it out on a piece of #Ruby that was written in a hurry for a personal project.

I asked the following prompt:

Prompt used for Claude Code

It created a new file that included the previous code and maintained the previous structure with private attr_reader, even though it wasn’t necessary here.

New file created by Claude Code

It then replaced the previous code with a call to the new object.
At least two notes:
- It is not necessary to use require relative since this is a Rails project
- It kept that method with a single call and here, I would have liked to discuss whether to keep it or not

The changes in the existing file

Then it copied the test from the previous big file to this one and added an extra test.
Notice not only here but in multiple files that it does not add new line at the end of the file.

The tests moved to the new file

It then executed the tests and wrote a summary.
I would have liked to have executed the test from the file where the code was extracted to ensure that the tests there still passed. I executed it manually, and it still passed.

Executing tests

The total cost for this operation 29 cents and it took 3 minutes. Well the number of minutes is not real because I stopped multiple times taking screenshots.

Total costs

Sleep can improve your productivity

We probably all know this, but let me remind you—and mostly myself—that getting a good night's sleep is one of the simplest ways to boost productivity.

Add a 30-minute walk in the morning, and you'll likely see a 3.14x or even 7.5x increase, at least. 

You decide!

When posting on Bluesky or Mastodon use hashtags

A gentle reminder: please use #Ruby or #Rails when posting about Ruby or Ruby on Rails on Bluesky and Mastodon.

It helps with content discovery, and the search works much better, IMO when looking for hashtags.

Include Hashtags

Let me add another thought: 

  • I recommend to tag with \#Ruby and \#Rails because Rails uses Ruby :) 
  • There should not be a need to say this out loud, but I discovered a lot of content tagged only with Rails, which says something about how massive Rails is in the Ruby world.

I am approaching this from the perspective of someone who, let's say, just found out about Ruby on Rails and tries to search on Bluesky or Mastodon.

If they search for #Ruby, they should also see #Rails content and get inspired about what they could achieve with it.


Why do I talk here about Bluesky and Mastodon? 
For example, Twitter or Linkedin have their own algorithm to push content, and I am not sure hashtags are any part of it. It seems to me that what matters there is the virality of the post. But if you post on Linkedin or Twitter please do add hash tags there too. 

PS: It works for other topics, too!

How grape-entity works

Someone asked on Reddit a question like:

> Can anyone provide me an informative article on how grape-entity works?

I don't know or not able to find an article that describes how it works.

Whenever I use it, and I have some doubts, I try to read the source code. 

You can start from here:
https://github.com/ruby-grape/grape-entity/blob/master/lib/grape_entity/entity.rb

But all the files in this folder https://github.com/ruby-grape/grape-entity/tree/master/lib/grape_entity are relatively easy to read.

In case you feel like having questions like "How did the entity got that value or what is the source of that value" I would recommend looking into the delegators https://github.com/ruby-grape/grape-entity/tree/master/lib/grape_entity/delegator

Consider carefully when deciding to create an array column in Rails

Think carefully about whether I truly need an array column in Rails or if it's more effective to create it as JSON from the start.

Sooner rather than later, I would like to enrich that column and add some extra information. 

Which will create the need for a 3-stage migration:

  • Add new column while keeping the old one 
  • Execute data migration by generating the new structure in the new column
  • Change the code to use the new column
  • Drop the original column

Before deciding, I should clarify the reasons this will always be an array instead of just assuming it is one. And if there are no good reasons for it maybe it should be a JSON/JSONB column from the start. 

Of course, could be that this should just be a nested model -> but that is a decision to be discussed in another post :)

Twitter transitioned to Scala to continue writing beautiful code

I found this quote in this article about Twitter moving to Scala:

> But he also prefers Scala because it's, well, beautiful. "It's a fuzzy thing. But we like writing beautiful code, code that you're proud of, code that you can show to non-programmers and they get it."

About Scala and writing beautiful code

They chose Scala because they wanted to write "beautiful code." 
I think I can say that Ruby influenced this decision in more ways than one.

Short Ruby Newsletter - Highlights from edition 117

🚀 Launches

  • Stanislav Katkov launched the website for poshtui.com
  • Lindsey Christensen launched the Hotwire Essentials
  • Sandi Metz announced a 40% discount for their books until 13 December
  • Martin Sojka launched codesnips.io
  • Andrey Eremin launched a new course Ruby on Types: Static Typing with Ruby and Ruby on Rails
  • Josef Strzibny announced that testdrivingrails.com - 1st edition is out

📅 Events:

  • RoRvsWild shared a map from Ruby meetups in Europe
  • Check RubyConferences.org/meetups as there 26 meetups this week only around the world
  • Ruby Central invites Ruby meetup organizers to apply for a grant
  • Balticruby announced CFP is open at papercall.io/balticruby25

👉 All about Code and Ruby

Ruby On Rails announced that The Rails Foundation welcomes 1Password as Core member.

There are a lot of code samples included; here are just some of them:

  • Drew Bragg shared a code sample about DATA constant in a Ruby file
  • Xavier Noria shared that Ruby already has “pipe operator" and that is the dot
  • Akash Manohar shared a tip about enabling debugging for Stimulus:
  • Prabin Poudel shared a code sample about accessing a helper method
  • Joel Drapper shared a code sample about defining a / method to lookup a record by using a Base64 id
  • Jamie Schembri shared a code sample about using StringInquirer from ActiveSupport
  • Joël Quenneville shared a code sample showing how converting to UTC changes a time value
  • Nate Berkopec shared a code sample about how IO/CPU interact with the GVL
    And there are so many more code samples. This edition is packed with interesting code samples, discussions about code design, and inspiration around code.

🧰 Gems, Libraries, Tools and Updates

  • Vladimir Dementyev published a new gem called wasmify-rails - Tools and extensions to pack and run Rails apps on Wasm
  • Sam Ruby announced a new gem called fly-atc - A SaaS toolkit for mutli-tenant production deployments with zero-config streaming backups
  • Alex Denisov shared their work on lightstorm: Minimalistic ahead-of-time Ruby compiler

You will also find updates on their projects or libraries from Rosa, who announced the 1.0 version of Mission Control Jobs, Avo, who announced version 3.15.0 with huge improvements, Bozhidar Batsov, who announced an update about Rubocop v1.69.1, Nate Hopkins, who announced an update about LocalBus v.0.3.0, and many more gem updates.

As always, we have more links to newsletters, videos, podcasts, and articles.

Read the full newsletter for free at https://newsletter.shortruby.com/p/edition-117


Written by Lucian Ghinda - Senior Ruby Developer by day, Curator of Short Ruby Newsletter during weekends