---
title: "A cookbook of Ruby one liners"
publication: "Ruby Weekly"
issue: 574
published_at: "2021-10-14"
canonical_url: "https://rubyweekly.com/issues/574"
---

Plus a Ruby to JS transpiler, embracing infinite loops, and how to upgrade to Zeitwerk. |        

#​574 — October 14, 2021 

[Read on the Web](https://rubyweekly.com/issues/574)   

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/mdasjwezjfuvunkdm2yb.jpg)](https://noteflakes.com/articles/2021-10-14-embracing-infinite-loops)  

[Embracing Infinite Loops with Ruby and Polyphony](https://noteflakes.com/articles/2021-10-14-embracing-infinite-loops) — See how infinite loops can be used as the basis for long running concurrent tasks here with [Polyphony](https://github.com/digital-fabric/polyphony), a io_uring/libev oriented concurrency library, doing the heavy lifting. 

Sharon Rosner   

▶[39 Talks from RubyKaigi Takeout 2021](https://www.youtube.com/playlist?list=PLbFmgWm555yYgc4sx2Dkb7WWcfflbt6AP#rubykaigi2021) — The popular RubyKaigi conference usually takes place in Japan each year but was held online again due to the ongoing world health problems. A wide array of both English and Japanese talks happened, including these: 

- [Building a new JIT Compiler inside CRuby](https://www.youtube.com/watch?v=PBVLf3yfMs8) by Maxime Chevalier-Boisvert.
- [A look at Rucy: A way to compile Ruby into BPF](https://www.youtube.com/watch?v=qvaXv8exFFQ) by Uchio Kondo.
- [Crafting exploits, tools and havoc with Ruby](https://www.youtube.com/watch?v=LIECErdtTDc) by Mauro Eldritch.
- [Parallel testing with Ractors](https://www.youtube.com/watch?v=bvFj6_dulSo) by Vinicius Stock. 

RubyKaigi   [![\](https://copm.s3.amazonaws.com/371dca39.png)](https://www2.reinteractive.com/opscare-hosting) 

[Complete Peace of Mind Rails Hosting](https://www2.reinteractive.com/opscare-hosting) — OpsCare is 100% peace of mind Rails hosting and support. Built on our 12-factor compliant custom stack, we provide comprehensive deployment, scaling and monitoring tools. OpsCare keeps your application performing, 24 hours a day - 7 days a week. 

OpsCare by reinteractive sponsor   

[Ruby2JS 4.2.0: A Ruby to JavaScript Transpiler](https://www.ruby2js.com/) — A transpiler aimed at keeping your code looking ‘hand crafted’ rather than merely transpiled. There’s a [live demo](https://www.ruby2js.com/demo) if you want to see it in action. 

Sam Ruby and Jared White   

**QUICK BITS:** 

- [RubyGems 3.2.29](https://blog.rubygems.org/2021/10/08/3.2.29-released.html) has been released.
- Gift Egwuenu shares [the latest monthly update from the RubyGems project](https://blog.rubygems.org/2021/10/13/september-rubygems-updates.html) focused around the release of RubyGems 3.2.27 and 3.2.28 and Bundler 2.2.27 and 2.2.28.
- The Gosu Ruby game jam, which we mentioned last week, [starts in just two days.](https://itch.io/jam/gosu-game-jam)
- [RubyMine 2021.3 EAP3](https://blog.jetbrains.com/ruby/2021/10/rubymine-2021-3-eap3/) has been released with editor performace improvements and more RBS-powered inspections.   

[A Ruby One-Liners Cookbook](https://learnbyexample.github.io/learn_ruby_oneliners/one-liner-introduction.html) — Ruby is a _fantastic_ language for one-liners, whether in IRB or even from the command line. This cookbook is an extension of a [epic list of them](https://github.com/learnbyexample/Command-line-text-processing/blob/master/ruby_one_liners.md) we’ve shared before, and it relates to our _Tip of the Week_ further down this issue too :-) 

Sundeep Agarwal     

Jobs  

[Principal Ruby Platform Engineer (Remote - EST Timezone +/- 3 hours)](https://www.linkedin.com/jobs/view/2255010679/?capColoOverride=true) — Interested in Fintech? Join our core team building the AI that will level the playing field for self-directed investors. 
Propelor   

[Senior Backend Software Engineer (Remote)](https://angel.co/company/sellwithami/jobs/1568454-senior-backend-software-engineer) — Design, develop, and extend our data integration framework and APIs to continue to onboard new AMI Customers and social sellers. 
Sell With Ami   

[Find Ruby Jobs Through Hired](https://hired.com/join/?utm_source=newsletter&utm_medium=sponsor&utm_campaign=%28b2c%29%28l-all%29%28r-all%29%28cooper-rubyweekly%29&utm_content=find-your-next-job) — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers. 
Hired    

📕 Articles & Tutorials  

[Upgrading to Zeitwerk](https://www.fastruby.io/blog/rails/upgrade/zeitwerk/upgrading-to-zeitwerk.html) — A walkthrough of what’s involved in upgrading a Rails 6 app from classic to Zeitwork mode, if you haven’t taken on Zeitwerk yet. 

Simon Chiu   

[Ruby Safe Navigation](https://thoughtbot.com/blog/ruby-safe-navigation) — Using the lonely (or safe) operator (`&.`) says some things about your code that you may not realize and, once you do, there may be a better way to say them. 

Joël Quenneville   

[Using DynamoDB in Your Rails App](https://www.honeybadger.io/blog/aws-dynamo-db-rails/) — Julie introduces DynamoDB and its concepts then closes by showing how using it can feel very much like Active Record. 

Julie Kent   

[A Way to Detect Early Returns from a Block](https://island94.org/2021/10/2021-10-11-til-detecting-block-returns-in-ruby) — An interesting little technique the author discovered via [this Rails PR](https://github.com/rails/rails/pull/29333). 

Ben Sheldon   

▶[Discussing _Polished Ruby Programming_ with Jeremy Evans](https://rubyrogues.com/polished-ruby-programming-ft-jeremy-evans-ruby-518) — Jeremy joins the Rogues to discuss his new book, [_Polished Ruby Programming_](https://www.packtpub.com/product/polished-ruby-programming/9781801072724), and his opinions on and best practices for Ruby development. 

Ruby Rogues Podcast podcast   

▶[A Team Looks at Reducing Memory Bloat in a Rails App](https://www.bigbinary.com/blog/reducing-memory-bloat-in-a-ruby-on-rails-application) — A team has shared an 11-minute, originally internal-use-only, video of a post mortem of a Rails memory bloat issue they experienced. 

bigbinary   

[Seamlessly Integrate Video into Your Ruby App](https://get.mux.com/3aubTJg) 

Mux sponsor   

[Organizing Business Logic in Rails with Contexts](https://nts.strzibny.name/business-logic-in-rails-with-contexts/) — Josef takes on the age-old conundrum of models vs service objects, adding a new take he gleaned from working with the Phoenix framework. 

Josef Strzibny   

▶[Discussing the Organization of Large Rails Apps with Jared White](https://codewithjason.simplecast.com/episodes/115-organizing-large-rails-apps-with-jared-white-DIQGZHGQ) 

Code with Jason Podcast podcast   

▶[How to Use Bootstrap with CSS Bundling in Rails](https://gorails.com/episodes/bootstrap-css-bundling-rails) 
Go Rails  

🛠 Code & Tools  

[redis-rb 4.5: The Ruby Client Library for Redis](https://github.com/redis/redis-rb) — The official Ruby client for the [Redis](https://redis.io/) data structure server. 4.5 adds support for a variety of command introduced in Redis 6.2 like `ZRANDMEMBER`, `ZMSCORE` and `SMISMEMBER`. 

Redis   

[JRuby 9.3.1.0 Released](https://www.jruby.org/2021/10/13/jruby-9-3-1-0.html) — The latest release of the Ruby 2.6.x compatible line of the JVM-based Ruby implementation. 

JRuby Core Team   

[A Better Way to Index Your Postgres Database: pganalyze Index Advisor](https://pganalyze.com/index-advisor?utm_source=RubyWeeklySecondary10142021) — Paste your query and schema data and the free pganalyze Index Advisor recommends the ideal index for your query. 

pganalyze sponsor   

[Informers: State-of-the-Art Natural Language Processing for Ruby](https://github.com/ankane/informers) — You can do sentiment analysis, question answering, name-entity recognition, and the latest feature is text generation. 

Andrew Kane   

[benchmark-ips: 'Iterations Per Second' Benchmarking for Ruby](https://github.com/evanphx/benchmark-ips) — Improves the standard Benchmark functionality. 

Evan Phoenix   

[DeadEnd: Searches for Unexpected `end` Syntax Errors](https://github.com/zombocom/dead_end) — This is a _very_ specific tool, but if unmatched `end`s are a particular bugbear of yours.. 

ZomboCom   

[Xcodeproj: Create and Modify Xcode Projects from Ruby](https://github.com/CocoaPods/Xcodeproj) 
CocoaPods       

💡**Tip of the Week** 

   

## Ruby's `-e` and `-c` command line options 

You will be familiar with running Ruby code saved in a file from the command line using `ruby filename.rb`. You'll also be familiar, especially if you follow along with the _Tip of the Week_!, with running snippets of code within different Ruby REPLs, such as `irb`, `pry`, `rails c` or something else. 

We can also run small snippets by passing the `-e` flag to `ruby` from the command line. For instance: 

```
$ ruby -e "puts 1 + 3"
4
``` 

The `-e` flag can come in handy if we're looking for a specific method, or just need a quick calculation, and don't necessarily need to open up a full REPL. 

This [guide to Ruby 'one liners'](https://learnbyexample.github.io/learn_ruby_oneliners/one-liner-introduction.html) provides a vast array of ways to use the `-e` flag along with others to achieve quite complex outcomes from the command line or shell script. 

Another useful flag is `-c` which will do a Ruby _syntax check_ on a file without actually executing the file. I find this useful when resolving git merge conflicts, as a way to double check that I haven't left any stray lines in my Ruby files. For instance: 

```
$ ruby -c some_file.rb
some_file.rb:1: syntax error, unexpected end-of-input
``` 

The `-e` and `-c` flags are two of many which we can use when running `ruby` from the command line. To see more options, run `man ruby` from the command line, and we will cover some more interesting ones in coming weeks too.    

This week’s tip was written by [Jemma Issroff](https://twitter.com/jemmaissroff).      

🕰 **ICYMI** _(Some older stuff that may catch your eye...)_ 

- If you want to use Ruby to consume ML models, then [serving Tensorflow over gRPC and generating a Ruby client from the protobufs](https://honeyryderchuck.gitlab.io/httpx/2021/08/26/tensorflow-serving-with-ruby.html) is one way to do that.
- [Here's a 3-part series](https://medium.com/invoca-engineering-blog/lessons-learned-in-a-major-rails-upgrade-strategy-1b0463ec41fc) that covers the strategy, management, and tooling of a major (a million+ lines of code) Rails upgrade (from 4 to 5, in this case.)
- Seeing [how Rails makes some of its syntactic sugar](https://longliveruby.com/articles/the-magic-behind-ruby-on-rails-code) will probably give you some inspiration to create your own. Is too much sugar a bad thing?
- [Logging URI Query Params with Lograge](https://bibwild.wordpress.com/2021/08/04/logging-uri-query-params-with-lograge/) is probably a bit more involved than you might initially guess.
- Matt Swanson highlights how to run different ActiveRecord validations [based on context](https://boringrails.com/tips/activerecord-validation-context).
- Does Rails owe its approach to an art philosophy that emerged at the end of WWII? _Maybe_. Regardless, [this is an interesting read](https://uxdesign.cc/bauhaus-influences-on-ruby-on-rails-doctrine-a-brief-story-92be49a5bfa4).         

Curated by [Peter Cooper](https://twitter.com/peterc), [Glenn Goodrich](https://twitter.com/ruprict) and [Cooperpress](https://cooperpress.com/). 

[Change your email address](https://rubyweekly.com/edit_subscription/*|UID|*) or[Stop getting this newsletter](https://rubyweekly.com/leave/*|UID|*) 

© Cooper Press Ltd · Fairfield Enterprise Centre, Louth, LN11 0LS, United Kingdom
