Short Notes
Short posts mostly about Ruby and Ruby on Rails. You can find me at : Linkedin, Mastodon, Twitter or for longer posts at allaboutcoding.ghinda.com
Subscribe via RSS here

Define reference to an Active Record that has a custom table defined

Here is a #Rails pro tip I discovered while trying to write a migration for defining a belong_to association to a model that had a custom table instead of relying on the Rails convention: The solution I found was to use an option called `to_table` defined on the `foreign_key` attribute of TableDefinition#references Documentation about this can be found at:  • Rails Guides - Active Record Migrations#foreign_keys • Rails Guides - Association Basics#self-joins • Rails API - SchemaStatements#add_reference

4 article recommendations about Ruby from week 10-16 June

If I would need to only pick 4 articles published in the previous week (10-16 June 2024) about Ruby, here is what I would read:  • Victor Shepelev article about The design decisions and evolution of a method definition - Ruby case study • Mathieu Eustachy article about Memory management explained in Ruby • Jp Camara article about Your Ruby programs are always multi-threaded: Part 1 • Josef Strzibny article about Understanding Kamal healthcheck settings But the good news is that I can read more than 4 :) as there are a lot more good articles in the More Content...

Endless Method - a short summary

Did you know Ruby 3.0 introduced the endless method? That was more than three years ago. It could be helpful sometimes for writing concise code! Let me show some use cases and see how it can improve code readability and structure.Before we begin, let's clarify: I'm not saying the endless method is better than traditional methods, nor that it could fit any case.  I am more interested in exploring how it can change the code shape.  One-line methods were possible in Ruby even before the endless method  Here are some examples of valid #Ruby syntax. Do we really need the...

Preparing for Ruby inline type signatures

There is a gem called rbs-inline that is exploring the idea of putting RBS inline in the source code instead of separate files. Andrey Eremin shared this first, and I just wanted to share it further with some extra screenshots.  Here is an example from the gem repo (syntax is experimental): The most important part is in the description of this gem, where it seems the plan is to experiment with inline RBS and then merge it to the RBS gem so we can have direct support for inline type signatures instead of only supporting separated files. Using Sorbet for...

Marketing and communication needs - research

 Are there people who have an idea for a product or are at the very beginning with it and have questions about marketing & comms but no budget & knowledge? Let’s talk, I’m thinking of something that might be helpful, and your input is important to ensure its relevance. Your questions, needs, and known unknowns are highly valued in this process to make sure we are creating something useful. I’m bringing in someone with knowledge in this area, and we’re in the research phase. It will be a short call, with a few brief questions, where you talk about your...

Short Ruby Newsletter - edition 93 published

Highlights from the 93 edition of Short Ruby Newsletter Events: EuRuko, RailsWorld, and BalticRuby announced the agenda and speakers. They have great lineups. Two returnees: Ruby Ireland and Barcelona.rb. SF Bay Area Ruby Meetup and Rails World Conf announced their next dates.  Ruby 3.1.6 and 3.3.2 are released. Rails 7.2 beta is announced. You can upgrade today to Ruby 3.3.2 and should start adding Rails 7.2 to your Read an article written by Why in 2003 posted by Nick Schwaderer last week where Why says why SQLite is amazing. Why was/is ahead of his time You can see some code...

Innovator's dilemma for programming languages

I was working on my slides about Discovering Modern Ruby Features early in the morning. As I brainstorm, I think about the innovator's dilemma and how it might apply to programming languages. It can be applied to any established language. As a programming language matures, it changes to stay relevant, address new problems, and improve usability. However, introducing new features or paradigms can disrupt the existing user base and ecosystem.Community Dynamics Long-time users of the language may prefer stability and backward compatibility. Newer users or those facing specific pain points may advocate for more radical changes to keep the language...

Short Ruby Newsletter - edition 91 published

There were many significant events in the #Ruby world last week, making the newsletter quite lengthy. It's hard to choose just one highlight, but here are a couple of points: • Ruby 3.4.preview was released, and strings will now behave as if they are frozen by default. • The refactoring of Array.each to Ruby code made it significantly faster than the C implementation. • Rails tagged the 7.2 branch, and development for Rails 8 has started. • Richard Schneeman wrote an insightful comment on Reddit explaining how Ruby GC works and recommended a list of articles for a deeper understanding....

Using a Case statement or Metaprogramming?

Matt posted this question: A case statement does not add complexity when thinking about readability or maintainability. I know that various tools will report it as creating too many branches (or paths), but to me there are situations where a case statement is the best way to say something explicitely with code.  Second, I assume that `phases,` `tasks,` and `gates` are ActiveRecord models, so the chances that this case will grow very quickly and very big are small.  On the other hand, introducing meta-programming may seem tempting as it can significantly reduce code length to a single line. However, it's...

Service Objects and Naming in Ruby

In OOP (maybe in functional, too - but I don't have the same years of experience with functional), naming objects is hard.  Naming a collection of objects that should do something together is harder too.  Just one exanmple when there are multiple objects that needs to be coordinated in a specific sequence:  • Is there another object on a different level that should compose them? • If so what is that object called? • Does that name exist in the business domain, or is it a code pattern? If such object can be found and properly named I would of...

Celebrating 4500 subscribers

Today I am celebrating 4500+ subscribers for Short Ruby Newsletter Huge thanks to the #Ruby community!What is Short Ruby Newsletter? It is a free Monday morning summary of articles, discussions, and news from the Ruby community. I watch a series of places, such as Twitter, Ruby Social, Reddit, LinkedIn, Dev to, and some other sources. If you want to see how an edition looks, you can browse all 85 editions published so far at https://newsletter.shortruby.com I invite you to subscribe if you have not done so already! You can see a short preview videos of how it looks like inside...

Using Bruno - the API client

I started using Bruno this weekend, and I enjoyed it very much. The biggest advantage for me is having all the collections stored in text files on my file system. SeeI  store them in a Rails app's/docs/requests folder. Works very well! Here is an example of what I defined in the project that I use to manage citations for Short Ruby Newsletter. This is how I defined a collection. Bruno uses their own markup language called Bru, which is similar to JSON in some ways. For instance, it uses key-value pairs to store data, just like JSON. I wanted the...

A small example about how Ruby is evolving

A small example about how #Ruby is evolving.  I took a code sample from a feature request from 2011 and wrote it using features that will be available in Ruby 3.4 In case you are wondering, `_1` is called a numbered block parameter, and in this case, it is a shorthand syntax for the first parameter in that block.You can play with `it` block param already using https://ruby-next.github.io Reply to this on Twitter, Mastodon, or Linkedin


👐 Subscribe to my Ruby and Ruby on rails courses over email at learn.shortruby.com- effortless learning anytime, anywhere


👉 Join my Short Ruby News newsletter for weekly Ruby updates from the community and visit rubyandrails.info, a directory with learning content about Ruby.


🤝 Let's connect on Ruby.social or Linkedin or Twitter where I post mainly about Ruby and Rails.


🎥 Follow me on my YouTube channel for short videos about Ruby