---
title: "Let's learn about RBS"
publication: "Ruby Weekly"
issue: 537
published_at: "2021-01-28"
canonical_url: "https://rubyweekly.com/issues/537"
---

Plus how Google Cloud added Ruby to Cloud Functions, and Rails goes from masterful to mainstream. |        

#537 — January 28, 2021 

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

💡 The _Tip of the Week_ is back! If you missed last week's, feel free to [step back in time](https://rubyweekly.com/issues/536), but otherwise this week's is at the end of the issue, as before. You might also want to [follow Jemma on Twitter](https://twitter.com/jemmaissroff) as she's currently writing a book about garbage collection and has posted some interesting tweets so far.
__
_Peter Cooper, editor_  

![](https://res.cloudinary.com/cpress/image/upload/e_grayscale,w_150,h_170,c_pad,g_south/xrupigpv8kyjqotfdgy8.jpg)    

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/shbqj2mfqi5mcetidnao.jpg)](https://blog.appsignal.com/2021/01/27/rbs-the-new-ruby-3-typing-language-in-action.html)  

[RBS: The New Ruby 3 Typing Language in Action](https://blog.appsignal.com/2021/01/27/rbs-the-new-ruby-3-typing-language-in-action.html) — We briefly covered what RBS was when Ruby 3.0 launched but.. it’s not the easiest thing to get your head around. This article goes into more depth and is a worthwhile introduction (and comparison to Sorbet) if _typed_ Ruby intrigues you. 

Diogo Souza   

[Designing a Ruby Serverless Runtime for Google Cloud Functions](https://daniel-azuma.com/blog/2021/01/20/designing-a-ruby-serverless-runtime) — A senior software engineer at Google digs into the design decisions and trade-offs involved in bringing Ruby support to Google Cloud Functions. 

Daniel Azuma   [![\](https://copm.s3.amazonaws.com/7b9d886f.png)](https://reinteractive.com/service/ops-care) 

[Complete Peace of Mind Rails Hosting](https://reinteractive.com/service/ops-care) — If you need 100% peace of mind Rails hosting, OpsCare is for you. Built on our custom stack with comprehensive yet flexible deployment, scaling and monitoring tools, we keep your application online and performing, 24 hours a day, 7 days a week. 

OpsCare by reinteractive sponsor   

[Logidze 1.0: Active Record, Postgres, Rails, and Time Travel](https://evilmartians.com/chronicles/logidze-1-0-active-record-postgresql-rails-and-time-travel) — The rather tricky to pronounce Logidze is a library that tracks changes made to tables managed by Active Record by way of Postgres triggers and a JSONB record. It proudly claims to be the _‘fastest gem for auditing models in the Rails ecosystem.’_ 

Vladimir Dementyev   

[How ActiveRecord Uses Caching To Avoid Unnecessary Trips to the Database](https://www.honeybadger.io/blog/rails-activerecord-caching/) — Jonathan talks about caches that we don’t need to mess with (counter cache, SQL action cache, lazy evaluation), but it’s good to know how to mess with it for edge cases. 

Jonathan Miles     

Quick Bits 

- GitHub has made it [easier to rename existing branches in repos](https://github.blog/changelog/2021-01-19-support-for-renaming-an-existing-branch/) – such as if you want to change `master` to `main`. Rails has [made the switch](https://twitter.com/dhh/status/1350091751789375490), says DHH.
- [RubyGems 3.2.7](https://blog.rubygems.org/2021/01/27/3.2.7-released.html) and [3.1.6](https://blog.rubygems.org/2021/01/26/3.1.6-released.html) have been released — minor bug fix releases. Run `gem update --system` as appropriate.
- There's a [new version of Awesome Print](https://github.com/awesome-print/awesome_print) (long thought abandoned) on the way, but there are some RubyGems account snafus to sort out first. We'll announce it once it's up!
- There's now a [Stimulus Reflex course](https://www.stimulusreflexpatterns.com/) in early access. It costs money but the creator asked us very nicely and this is a topic area not well served yet.  

📘 Articles & Tutorials  

[`Object#tap` And How To Use It](https://www.rubypigeon.com/posts/object-tap-and-how-to-use-it/) — I think my favorite part of this explanation of this oft-confusing method is the reasoning behind its name, which now makes perfect sense. 

Tom Dalling   

[What Week Is It Anyway?](https://blog.rebased.pl/2021/01/25/what-week-is-it-anyway-1.html) — Working with dates and times is hard. Time zones and mind-bending edge cases make tests flaky and bugs hard to reproduce. This two-part series walks through two such cases. Did you know that some years have 53 weeks? 

Barbara Litwińska   

[Some Interesting `throw`/`catch` Behavior](https://janko.io/interesting-throw-catch-behaviour-in-ruby/) — Did you know that catching a `throw` means none of the `rescue` clauses are executed? 

Janko Marohnić   

[Find Out What Developer & Community Relations as a Service Can Mean](https://devrelate.io) — We help build and work with communities through content, events, podcasts, and more. Get your message to the right people now. 

DevRelate.io sponsor   

[How to Run Tests in Parallel on GitHub Actions](https://rubyyagi.com/how-to-run-tests-in-parallel-in-github-actions/) — An advanced use case for GitHub Actions right here. 

Axel Kee   

[How to Memoize Expensive Code](https://andycroll.com/ruby/memoize-expensive-code/) — A nice reminder of a basic performance improving technique. 

Andy Croll   

[Rails 6.1 Improves Support for Postgres' Interval Data Type](https://bigbinary.com/blog/rails-6-1-adds-postgresql-interval-data-type) — The code to do this is now much easier to read. 

Akhil Gautam   

[Two Patterns for StimulusReflex Form Submissions](https://blog.minthesize.com/two-patterns-for-stimulus-reflex-form-submissions) — This presumes you are somewhat comfortable with StimulusReflex, providing a way to handle your form submissions in a reusable manner. 

Julian Rubisch  

🛠 Code and Tools  

[mini_phone: A Fast Phone Number Library for Ruby](https://github.com/ianks/mini_phone) — mini_phone uses Google’s libphonenumber so it’s very fast, integrates with ActiveRecord, and aims to be a drop-in replacement for Phonelib (another phone number gem.) 

Ian Ker-Seymer   

[Chaskiq: A Rails + React Powered Conversational Marketing Platform](https://github.com/chaskiq/chaskiq) — Imagine an open source, self hosted version of Drift, Intercom, and the like. It’s now up to Rails 6.1 standards and there have been a few releases since we mentioned it last. An interesting example of a large scale, open source Rails app. 

ChaskiqHQ   

[Founders/CTO’s Slow or Failing CI Killing Productivity? We Can Help](https://hint.io/helps-you-ship-code) 

Hint sponsor   

[Brakeman 5.0.0: A Security Vulnerability Scanner for Rails Apps](https://github.com/presidentbeef/brakeman) — A list of [what’s new in today’s release.](https://github.com/presidentbeef/brakeman/releases/tag/v5.0.0) 

Justin Collins   

[Rack::Attack 6.4.0: Rack Middleware for Blocking and Throttling](https://github.com/rack/rack-attack) — This release brings Ruby 3.0 support and drops Ruby 2.3. 

Rack Project   

[ruby-dns-mock: Mimic Any DNS Records for Your Test Environment](https://github.com/mocktools/ruby-dns-mock) 

Vladislav Trotsenko  

💻 Jobs  

[Senior Ruby Engineer (Remote, EU Time Zones)](https://grnh.se/66883dfc2us) — Read how we balance life/work and what our values are. Maybe we can pique your interest to join our remote team and help make accountants’ work more meaningful. 

Silverfin   

[Full-Stack/Backend Software Engineer (Fully Remote/US)](https://jobs.lever.co/IsometricTechnologies/ced96d5d-6249-433e-9a18-eab0820ad388?lever-origin=applied&lever-source%5B%5D=Ruby%20Weekly) — Small team innovating supply chain collaboration for Fortune 1000 companies. Former Uber Freight founders. Built with empathy and no egos. 

Isometric Technologies   

[Find Your Next Job 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   

ℹ️ _Interested in running a job listing in Ruby Weekly? There's [more info here](https://booking.cooperpress.com/jobs)_.     

💡**Tip of the Week** 

Using `Comparable#clamp` to limit a value to within a range 

Forcing a value to fall within a range became a whole lot easier when Ruby 2.4 introduced `Comparable#clamp`. 

`Comparable#clamp` takes `min` and `max` arguments. If the value we're "clamping" is within the `min` and `max`, `Comparable#clamp` returns the value unchanged. Otherwise, if the value is less than `min`, `Comparable#clamp` returns `min`, and if the value is greater than `max`, `Comparable#clamp` returns `max`:  

1.clamp(0,3)
 => 1
 
 1.clamp(2,3)
 => 2
 
 "jemma".clamp("a", "z")
 => "jemma"
 
 "jemma".clamp("a", "j")
 => "j"   

And then, just when we were getting really excited about `Comparable#clamp`, Ruby 2.7 gave us even more to work with! As of Ruby 2.7, `clamp` can also take an inclusive `..` (not exclusive `...`) range of values. 

Notably, nil can be within this range. `val.clamp(..max)` will be the equivalent of taking the minimum of `val` and `max`. And vice versa. Let's take a look:  

1.clamp(2..3)
 => 2
 
 1.clamp(..3)
 => 1   

And lastly, just as a reminder, the [Comparable mixin](https://docs.ruby-lang.org/en/3.0.0/Comparable.html) is used by classes whose objects can be comparaed and therefore ordered. If you'd like to have `clamp`ing work for a class you've written, be sure to `include Comparable` and define the `<=>` operator. 

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

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
