Short Ruby - edition #19 - the full edition

Briefly about everything happening in Ruby world

This edition was created with support from @adrianthedev from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and @jcsrb

It is excellent to start the week with something positive:

👉 Adrian Marin shared a suggestion about how to contribute to supporting more people to user Ruby:

People keep asking what's the best thing to do to ensure more people work with Ruby in the future. Answers like "build more things in Ruby", "contribute to Open Source projects" are vague, not clearly defined, and un-actionable. Create an apprenticeship program for developers who are still in school. They usually want to learn how "real-world" development is being done and are eager to learn. Make Ruby the first programming language for them and you'll have a passionate Ruby-ist for life.

It will help if you read the entire conversation as good ideas are replied back and forth.

👉 Peter Solnica shared a sample code of how the dry-logger reporting looks like:

👉 Ruby On Rails shared the news about Rails Foundation:

The Rails Foundation kicks off with one million dollars from @cookpad , @doximity , @fleetio , @github , @intercom , @procoretech , @Shopify , and @37signals to improve the documentation, education, marketing, and events in our ecosystem 🎉

If you want to read also about concerns regarding this foundation, here is a conversation started by Luca Guidi and here is one started by Brandon Weaver.

TIL that the Ruby Core monthly meeting notes are public and kept in a github repo:

👉 Miron Marczuk shared a thread about the course “Get to Senior” from HexDevs:

Recently, as a part of my career development, I enrolled on the course “Get to Senior” by @HexDevs. It is a fantastic resource in the #ruby community. It provides insight into the careers of some of our technology's most influential developers. Well done @HexDevs 👏

Here is a bit from the thread shared by Miron:

We start with the one and only Aaron Patterson (@tenderlove)! 1️⃣ From his experience, his promotion was closely related to developing leadership skills, rather than technical skills. Thus, if you want to improve: take the lead, start giving advice. “Re-balancing a tree wouldn’t get me promoted to the Senior. 2️⃣Staying in one job gives you more opportunities to grow - and having a manager who provides valuable feedback is crucial. Also, don’t forget to request that feedback! Ask questions like: - How can I be more involved? - How can I help? - How can I improve?

👉 Noel Rappin shared that The Pragmatic Bookshelf is having a Black Friday, and now you can buy Ruby books with a discount:

Pragmatic Press is starting their annual November sale today. Starting now and through November all ebooks are 40% off with code "turkeysale2022". That's a lot of great technical books, and I really hope you'll check out the whole slate. I have four books in print right now

You can now buy the Programming Ruby 3.2 pickaxe book with 40% discount using that code.

👉 Paul Mucur shared how to get the mime type from the Accept header:

Here he shared a gist showing how to use this in a controller with specs explaining how it works.

👉 Kirill Shevchenko shared a code sample showing the difference between == and .equal?

Difference between equal? and== Both are used to compare data, but: 1. == will return true if both objects contain the same value 2. equal? checks if references point to the same object in memory (both values are the same object)
== may perform type coercions whereas eql? does not: irb(main):005:0> 1== 1.0 => true irb(main):006:0> 1.eql?(1.0) => false

👉 Joel Drapper shared their take on React and View layer on Rails:

I’ve done a lot of technical interviews at companies using Ruby / Rails recently and one thing seems clear to me: on the current trajectory, React is set to be *the* Rails view layer. Hotwire gets us a long way towards SSR reactivity, but partials don’t cut it. Add to that the fact it’s quite difficult to hire Rails front-end developers and Shopify / GitHub have basically abandoned SSR, CTOs are sadly picking React.

You should read the conversation on ruby.social it has some excellent arguments for using ViewComponent or Phlex.

Later on Joel added:

Here’s the thing, it’s not that *anything you can do in React can be done in Hotwire.* Rather, you’re doing a million things in React that don’t need to be done because they don’t actually serve anyone’s needs. We spent so long designing the perfect React modal, no one stopped to consider the fact that modals provide an awful, frustrating, inaccessible user experience and we should use a different pattern like rendering a new page or providing an “undo” feature instead.

👉 Kirill Shevchenko shared a code sample about using split with a second argument:

Ruby's split method mostly used with the first argument like "one two three".split(" "). However, you can specify a second argument, which is used to limit the resulting array. There is a classic example of mapping the full name into two fields.

👉 Paweł Dąbrowski shared a code sample about how dig works:

Use the full power of Ruby's Hash#dig #RubyOnRails #100DaysOfCode #DEVCommunity #Ruby #Rails #100daysofcoding #100dayschallenge #CodeNewbies #longliveruby #coding #programmingisfun

👉 Greg Navis shared code samples about methods similar to method_missing:

💡 Ruby tip: method_missing has 10+ brothers and cousins. There are more than 10 hook methods that get called in response to certain events. ⬇️ Let's have a quick look at each one along with code examples.

Here is the list that Greg will demo with code samples in this thread:

  • method_added - “Invoked as a callback whenever an instance method is added to the receiver”

  • method_removed - “Invoked as a callback whenever an instance method is removed from the receiver”

  • method_undefined - “Invoked as a callback whenever an instance method is undefined from the receiver.”

  • prepended - “The equivalent of included, but for prepended modules.”

  • included - “Callback invoked whenever the receiver is included in another module or class.”

  • extended - “The equivalent of included, but for extended modules.”

  • singleton_method_added - “Invoked as a callback whenever a singleton method is added to the receiver.”

  • singleton_method_removed - “Invoked as a callback whenever a singleton method is removed from the receiver”

  • singleton_method_undefined - “Invoked as a callback whenever a singleton method is undefined in the receiver.”

  • method_missing - “Invoked by Ruby when obj is sent a message it cannot handle.”

  • const_missing - “Invoked when a reference is made to an undefined constant in mod.”

  • respond_to_missing? - “Hook method to return whether the obj can respond to id method or not.” - please notice the docs say “DO NOT USE THIS DIRECTLY”

You should read the entire thread where Greg shares code samples about each method.

👉 Justin Searls shared that our decision process is influenced by DevRel and megacorps:

One reason I withdrew a bit from the JavaScript Community® and chose to reinvest in Rails was that front-end frameworks and tooling became dominated by megacorps whose DevRel people convinced everyone that EVERY team should adopt solutions designed for Google or Facebook scale.

Related to this subject, Nate Hopkins shared this:

👉 Paweł Dąbrowski shared a visual explanation about the semantic versioning of gems in the Gemfile:

Curious about what these numbers in Gemfile stand for? It's called semantic versioning: Patch version change - fixed bug Minor version change - new feature Major version change - new version breaks the previous API #RubyOnRails #100DaysOfCode #DEVCommunity #Ruby #Rails

👉 Sebastian Wilgosz shared they plan to start a new podcast, focused on content creation for devs:

We're going to start a podcast focusing on #contentcreation for #devs. We'll talk a lot also about #ruby, #workflows, and things around that... But need a decent name for it. Any ideas?

If you are interested in this content, you should fill in this form where Sebastian wants to find out what you want to know.

👉 Brad Gessler shared a thread where he showed how to build a view for a form with Phlex.fun:

Got the prototype working! The form object tracks which fields you’ve used, creates a permitted params hash, signs it, and stuffs it into a hidden `permitted_params` input field. When the form is submitted, Rails verifies the params and stuffs them into `params.permit`

Here is a code sample Brad shared for how the controller might look like, but you should read the entire thread as it has more code samples about how to use Phlex components:

👉 Ruby Cademy shared their project rubycademy.com is now live:

https://t.co/dHWrof7XIL is now live! RubyCademy is a learning center for developers such as self-taught Rubyist, post-bootcamp dev, looking for first dev job, young graduate, junior or mid-level dev and who want to consolidate their knowledge of #Ruby and #RubyonRails.

👉 Leastbad shared a one-line config for Rails that will enable Brotli gzip content-encoding:

Add this to your config/application.rb to enable Brotli gzip content encoding in your Rails app: config.middleware.insert_after ActionDispatch::Static, Rack::Deflater ~70-90% compression on your HTML payloads.

Before enabling this, you should read about The BREACH attack

👉 Kevin Newton shared a code sample about how to use emojis as methods:

Ever wanted to use emojis as methods and be able to add them together? They're completely accepted as identifiers in Ruby, so you can use them as method names and local variable names.

👉 Jason Charnes asked a question about weekend projects in Ruby:

Y'all doing any cool #ruby stuff this weekend?

You will discover in the thread a wide range of exciting projects: from preparing to launch Hanami 2.0, finishing a workshop on TurboNative, working on documentation for TurboReflex, compiling C into Ruby, building a Roda starter for Fly.io deployments, using TracePoint, working on a new book and much more.

👉 Kirill Shevchenko shared a collection of tools to debug memory issues:

If you ever faced with debugging memory issues with ObjectSpace, there are 4 tools that provide a powerful interface on top of it: 1. memory_profiler 2. heapy 3. derailed_benchmarks 4. heap-profiler (links in thread)

Here is the list of gems with links:

👉 u/campbellm asked a question about how to use service objects and received a lot of good responses:

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 Warner shared their thoughts about monolith and micro-services architecture:

I'm convinced that one of the biggest architectural mistakes of the past decade was going full microservice On a spectrum of monolith to microservices, I suggest the following: Monolith > apps > services > microservices So, some thoughts

Here are some parts of the thread, but you should read it all:

🤝 Ryan Bates shared that it is possible to ignore specific commits while git blame: Read the docs here

Here is the relevant section from the Github docs:

🤝 Mel Kaulfuß shared what shift-left looks like:

“Shift Left -> do a thing that’s traditionally done at a later stage of the process and try do it earlier.” @AnthonyRees encourages us to think differently about how we do things! The results might surprise you.

🤝 Alex Russell shared about a new concept named Minimal Client Complexity:

I need to blog about the Principle of Minimal Client Complexity, but one way to understand why I push back so hard on huge stacks of JS is that when you move thing to the client, you don't add risks from each uncontrolled dimension, you _multiply_ them. What are those risks?

Here is one of those risks, as Alex mentions it, but you should read the thread:

🤝 Study Every Da shared how to open all changed files in vim:

Git alias I'm trying out - Open the files changed in a commit in vim tabs. So I can do something like `git go head` to pick up where I left off. If there's a way to do this already with fugitive LMK

It is worth considering this reply from Ara Hocopian:

This is how I do it for WIPs and HEAD. Maybe there is something of value that you can adapt to your needs. I'd also be interested to see how others do it.

🤝 Mosquito Capital shared a good thread about how to think and approach reliability scenarios:

I've seen a lot of people asking "why does everyone think Twitter is doomed?" As an SRE and sysadmin with 10+ years of industry experience, I wanted to write up a few scenarios that are real threats to the integrity of the bird site over the coming weeks.

If you read that thread, you can easily extract a checklist about what to check or how to test your system and see if you have the proper processes and people to handle these unexpected scenarios.

Articles and Videos

Something to read

Newsletters

🗞️ Nate Berkopec published a new edition of Speedshop Ruby Performance Newsletter: When Not To Use A Background Job

🗞️ Ruby Weekly published a new edition The Rails™ Foundation

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

🗞 Ruby Radar published a new edition: 77 - The Rails Foundation Announced

✍🏾 Articles

Andreas Haller shared an SQL gist explaining cursor-based pagination: Example implementation of cursor-based pagination

Code Climate published a new article written by Sasha Rezvina about Why Ruby Class Methods Resist Refactoring

Something to watch 🎥 or listen 🎧

Videos

🎥 Avdi Grimm published the first episode on the GracefulDev Youtube channel: Barewords in Ruby

Audio & Podcasts

🎧 Fuzzygroup re-launched the Ruby5 podcast Listen here

🎧 The Bike Shed published a new episode 362: Prioritizing Learning

🧰 Gems, Libraries, and Updates

Meg Gutshall shared the prettier_print gem that can replace the prettyprint gem.

Marco Roth shared that their PR about Outlets API was merged to hotwire/stimulus:

Stan Lo shared they are working on adding the edit command to IRB. Check out the PR Add edit command by st0012

Joel Drapper shared an example of how easy it is to re-use Phlex views as gems: See the code here

Stanislav Katkov shared an update of their gem rdoc-markdown where they added output examples. See example 1 and example 2

Joel Drapper shared they merged a PR that adds around_template hook on Phlex: Check out the PR here

Stephen Ierodiaconou published a new gem named yaml_csp_config that “allows you to specify your content security policy (CSP) in a YAML file”.

Reply

or to participate.