๐Ÿ‘‹ Issue #11 - 19-25 September 2022

The one with with Phlex components

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.

๐Ÿ‘‰ Schwad shared how quick it is to prototype ideas with Rails 7:

've been doing some work on a Rails 7 Bootstrap 5 application this month and I am _loving_ life. The loop from idea-to-feature is so short. If I need something fancy I can literally just reach over and grab hotwire. If I need a component I just go to the bootstrap docs. โค๏ธ

๐Ÿ‘‰ Brad Gessler shared a snippet of code that will help you not leak instance variables in partials in Rails:

You can check a working example on the public project Brad shared on Github.

๐Ÿ‘‰ Emmanuel Hayford explained what is the meaning of the i in the shorthand syntax for creating an array of symbol %i[]:

You use the `%i[]` syntax all the time to create an array of symbols, but what's the meaning of the 'i'? Where does it come from? The 'i' means "intern".

๐Ÿ‘‰ Thiago Massa shared a code sample about doing a direct grep in tasks:

mall Ruby on Rails tip. ๐Ÿ’ก Ever ran rails --tasks | grep my_task? This isn't really needed โŒ and there's an easier way to achieve the same result โœ…

๐Ÿ‘‰ Kevin Newton shared shared a proposal for implementing NilClass in Ruby and it seems to be faster when done this way:

Here is how it will look like:

class NilClass # # call-seq: # nil.to_i -> 0 # # Always returns zero. # # nil.to_i #=> 0 # def to_i return 0 end # # call-seq: # nil.to_f -> 0.0 # # Always returns zero. # # nil.to_f #=> 0.0 # def to_f return 0.0 end end

Read more about this including the benchmark run in the Ruby master ticket.

๐Ÿ‘‰ Kirill Shevchenko shared code sample about a common useful pattern when using Service Objects to encapsulate initializer in a call on the class:

if you are using the callable Service Object pattern, you can encapsulate the "new" method with private_class_method #ruby

In the same thread two gems that are helping to do this were shared: serviz and operators-service

๐Ÿ‘‰ Vinicius Stock shared thread with VSCode tips for Ruby:

  • โ€œCMD + SHIFT + O: fuzzy search symbols on a fileโ€ - source

  • โ€œCMD + T: fuzzy search symbols everywhereโ€ - source

  • โ€œF2 for renaming local variables, instance variables, methods or constantsโ€ - source

๐Ÿ‘‰ Martin Spickermann shared about bang method a quote from Matz:

A quote from Matz - Ruby creator - saying: "The bang (!) does not mean โ€œdestructiveโ€ nor lack of it mean non destructive either. The bang sign means โ€œthe bang version is more dangerous than its non bang counterpart; handle with careโ€. Since Ruby has a lot of โ€œdestructiveโ€ methods, if bang signs follow your opinion, every Ruby program would be full of bangs, thus ugly."

I tried to find the original source for this and it appears to be this forum discussion.

๐Ÿ‘‰ Emmanuel Hayford shared a code sample showing how super_method works:

In Ruby, there's `super`, quite common... but there's also `super_method`, that returns a `Method` of superclass which would be called when `super` is used or `nil` if there is no method on superclass.

๐Ÿ‘‰ Kirill Shevchenko shared about using retrying in Ruby by using retriable gem:

In modern application architecture, when working with external / internal API services, the use graceful retries with exponential backoff is a must. retriable is a great #ruby gem that helps with this.

๐Ÿ‘‰ Marco Roth shared a small and very pre alpha library to transform ERB into Phlex. Source code can be found here and you can play online with it at phlexing.fun:

๐Ÿ‘‰ Shino Kouda shared using `app` and `helper` methods in Rails console:

To give access to some functionalities that are only available in various contexts, like named route helpers and view helper methods, the Rails console provides "app" and "helper" instances.

๐Ÿ‘‰ Brad Gessler shared a code sample showing the nested layouts technique inspired from middemanapp:

Composing Rails layouts with partials or `content_for` has always felt clunky to me, so I stole the โ€œNested Layoutsโ€ technique from https://t.co/MconqgZDBG and got it working in Rails. Hereโ€™s what it looks like
# code from https://twitter.com/bradgessler/status/1572309688699715584 module Layouthelper # Render a block within a layout. This is a useful, and prefered way, to handle # nesting layouts, within Sitepress. def render_layout (layout, **kwargs, &block) render html: capture(&block), layout: "layouts/#{layout}", **kwargs end end <!-- This can be used in views like this: code from https://twitter.com/bradgessler/status/1572309684421554176 --> <!-- /apps/layouts/body.erb.html --> <!DOCTYPE html> <html> <head> ... </head> <body> <%= yield %> </body> </html> <!-- /apps/layouts/application.erb.html --> <%= render_layout "body" do %> <header> <h1>The International Website of Pancakes </header> <%= yield %> <footer> Brad was hungry when he created this demo app in 2022 </footer> <% end %>

 Check the playground created by Brad on Github for a more detailed explanation of how this works.

๐Ÿ‘‰ Greg Navis shared a validator with a proc that returns allowed values:

The inclusion validator in Rails accepts a Proc that receives the validated model and returns allowed values. Inspired by @manume's bug report against active_record_doctor. Thank you for contributing!

๐Ÿ‘‰ Eric Berry shared a code sample about how to chain operations in Ruby:

Joel Drapper shared an alternative for chaining using conditional object yielders:

๐Ÿ‘‰ Moses Gathuku shared a code sample about using conditionals to set classes:

Rails > 6.1 tag builder uses token_list to conditionally set classes. Check this example and read more on Boring Rails

 ๐Ÿ‘‰ Kirill Shevchenko shared how to use JSON.parse and parse into a custom array and hash classes:

The JSON.parse method returns a Hash for any object and an Array for any json array. However, you can parse JSON into custom structures by passing them to arguments object_class and array_class.

When using OpenStruct please be aware that it comes with a performance penalty.

 ๐Ÿ‘‰ Nate Berkopec shared advice about the number of processes per contain and preforking webservers:

Gonna keep beating this drum but 1 process per container does not apply to preforking webservers. Fork away, baby!

And Andrey Novikov added an explanation:

 ๐Ÿ‘‰ Brad Gessler shared a thread about using your component systems/libraries over for example simple_form or any building gems:

Oh and if youโ€™re wondering what the key insight is here โ€ฆusing rails building gems like simple_form to use guides.rubyonrails.org/form_helpers.hโ€ฆ results in a lot of unnecessary complexity. When you donโ€™t try using those Rails form helpers, you get much better results.

He later on shared some experiments he did with Phlex that will land later in the sitepress.cc.

Here is an example of a Phlex component that will rend a markdown:

You can find the code in his view-playground on Github. Joel suggested in the thread that the result of Rouge to the syntax highlighting is cached, thus having a slight performance improvement when rendering.

 ๐Ÿ‘‰ Mike Perham asked if anyone is actively working on removing Global VM Lock/GVL (also named Global Interpreter Lock/GIL) in Ruby:

Is anyone actively working on GVL removal in Ruby, to get a true multi-core CRuby? I would be interested in sponsoring this effort. Python is making progress...

He described the primary use case of this change as regarding Rails app that canโ€™t scale without managing multiple processes.

Here are two replies from Yukihiro Matz and Jean Boussier (please read the entire conversation for more context)

The last time we tried, removing GVL made Ruby significantly slower. If the Python community succeeds in making it faster, we will follow.
In addition, Ractor is a Ruby counterpart of Python's sub-interpreter. So in a sense, we have already removed GVL.

 ๐Ÿ‘‰ CJ Avilla shared a Github repo where he played with Phlex and Sinatra:

I'm OOO today and had a chance to play around with @joeldrapper's Phlex + Sinatra Fun stuff! Reminds me a bit of the DSL we used at Stripe for the old ERB docs (before we moved to Markdoc.dev)

You might want to check this Github Repo created by Ren Guoy where the deploys some Phlex.fun components on AWS Lamdba using Serverless.

๐Ÿ‘‰ David Colby shared that among the biggest changes in Turbo 7.2.0 is the ability to respond to a GET request with Turbo Stream:

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

Related (but not Ruby specific)

๐Ÿค” Brandon Weaver shared about growth and learning 

A fact, often forgotten, of the tech industry: you don't _need_ to read everything, listen to podcasts, attend conferences, or any of that to be good at your job. You're allowed to just exist.

And it got some interesting replies:

๐Ÿค” Nate Berkopec asked a question about DX and automating dev workflows:

A summary of the answers that were written as reply to the question:

๐Ÿค” Shopify Engineering asked about:

Here are some answers (including them here does not mean I agree with all of them, but I think they are interesting to think about).

Read the entire conversation, it had some interesting ideas; and I always like to challenge my beliefs/principles and think about what I miss or what I have to learn.

๐Ÿค” Simon Willison shared asked about how to explore a CSV file with 100_000 rows 

If someone gives you a CSV file with 100,000 rows in it, what tools do you use to start exploring and understanding that data?

He shared his solution to this question, but there were a lot of ideas in the conversation.

๐Ÿค” Brandon Weaver wrote about how to promote as a senior:

Ask early, ask often, and keep a cadence on conversations about gaps between you and that next level. Managers won't remember every detail so write it down and keep a track sheet of evidence. It's a collaborative process, and the higher level the more you need to contribute.

๐Ÿค” Jerome Hardaway shared that engineering management is as simple as going to all the meetings so the team does not have to:

Engineering management is basically going to all the meetings so the rest of the team doesnโ€™t have to.

๐Ÿค” Collin shared an alias for resolving merge conflicts with Vim:

Here's a nifty little alias for resolving merge conflicts with Vim ๐Ÿ˜Š:

๐Ÿค” Thomas Steiner shared a draft PR about implementing importmaps in WebKit:

๐Ÿ‘€ Oh, a draft PR that adds import maps (https://t.co/GxMpSNQjY8) to @WebKit: https://t.co/GxMpSNQjY8. Nice!

Articles and Videos

Courses or Books or Communities

๐ŸŽค Paweล‚ Dฤ…browski shared the deck he used when delivering the โ€œSidekiq on the surface and under the hoodโ€ presentation at @wrocloverb this year. See it here

๐Ÿ“’ Hanami Mastery shared they are opening access for Hanami Mastery PRO - a way to support their work and also get learning benefits in exchange (early access to courses and books, community access, priority support, and more). Join here.

๐ŸŽค Ruby Conf Mini shared in a series of tweets on this main thread the speakers at RubyConf Mini. Read the thread to learn more about the speakers and the topics they will address.

Something to read

Newsletters

๐Ÿ“– Aurelie Verrot shared they launched 35 edition of Women on Rails. Read the english version here. This edition has the content localized in French, Italian and  Spanish 

๐Ÿ“– Greg Molnar shared they released the latest This week in Rails

๐Ÿ“– Andrew Mason shared a new number of The Ruby Radar: #69 Turbo Brisket

Articles

๐Ÿ“– Sam Ruby shared a technology preview of what he calls โ€œTerraforming Railsโ€. It is worth reading the RFC for this where Sam explains what he tries to achieve and maybe also see the video demo of the current state of this tech where he deploys to fly.io a newly created Rails 7 app. I think (just a personal opinion) that this is very close to a concept that we could name ActiveDeployment.

๐Ÿ“– Colin Loretz shared an interactive tutorial he found about practicing PostgreSQL skills: Enhance your Postgres skills

๐Ÿ“– Kevin Murphy shared an article they wrote about organising RSpec test doubles. Read Symmetric Spies: RSpec Test Organization

๐Ÿ“– David Colby wrote an article showing infinite scroll with Rails, Turbo Stream and Stimulus by using Turbo 7.2.0. He also shared another article he wrote about Building a modal form with Turbo Stream GET requests.

Something to watch ๐ŸŽฅ or listen ๐ŸŽง

Videos

๐ŸŽฅ Aaron Patterson announced he would do a live stream with Vinicius Stock. Subscribe here to be notified when it will start.

๐ŸŽฅ Hanami Mastery shared their first episode of Hanamy Mastery PRO about working with ROM repositories. See Leverage ROM repositories

๐ŸŽฅ Wroclove.Rb shared all videos from 2022 edition. See wroc_love.rb 2022

๐ŸŽฅ Adrian Marin shared his presentation at Wroclove.rb about engine automation. See How To Package A Rails Engine Generation To Automation

๐ŸŽฅ Yaroslav Shmarov (Supe Rails Yt) shared their video presentation from WrocLove.rb about using hotwire and viewcomponent in production. See 18 months of using hotwire and viewcomponent in production

๐ŸŽฅ Drifting Ruby shared the video newsletter for This Week in Rails. See This Week in Rails Sept 23rd, 2022

Audio & Podcasts

๐ŸŽง Jason Swett shared the latest episode of Code with Jason where he talks with Alex Evanczuk about maintaining large Rails apps. Listen 162 - Large Rails Apps 

๐ŸŽง Ruby For All shared a new episode about Continuous Integration. Listen Episode 9 - Getting Started with Continous Integration. If you want to find reasons to listen to this podcast, you should check this discussion, where many people gave lovely feedback about this podcast.

๐ŸŽง Andrew Mason shared a new episode of Remote Ruby where they discuss Storybook, Tailwind, components, JIT and Purge CSS. Listen You Gotta Risk It For The Brisket

๐ŸŽง Joel Quenneville shared a new episode for The Bike Shed where he talks with Geoff Harcourt about test infrastructure and faster CI. Listen 355: Test Performance

Gems, Libraries, and Updates

๐Ÿงฐ Koichi Ito shared the latest release of Haml 6, which is faster 1.7x than Haml 5. Read changelog 

๐Ÿงฐ Tim Riley shared Hanami 2.0.0.beta3, which now supports reloading inside the console. Read changelog

๐Ÿงฐ DHH shared that Turbo 7.2.0 was released and it has a lot of new features and bug fixes. Check the release changelog

๐Ÿงฐ Nate Hopkins shared that he is working on two libraries  TurboReady adding more power to Turbo Streams, and TurboReflex, adding more power to Turbo Frames.

Here are some code samples from TurboReady:

And here are some examples from TurboReflex:

๐Ÿงฐ Adam shared a new library that allows writing web, mobile, and desktop apps powered by Flutter by writing Ruby code. So far, the core works but supporting the UI is still WIP. See the project here.

๐Ÿงฐ Joel Drapper shared they released Phlex.fun version 0.2.2. Read the changelog.

๐Ÿงฐ Kasper Timm Hansen announced a new version of active_record-associated_object gem. It now supports code to remove Active Job boilerplate:

๐Ÿงฐ Sinatra released version 3.0.0. Read the changelog.

Please consider sharing this on social media or with your colleagues:

Reply

or to participate.