---
title: "DHH on the future of JavaScript in Rails"
publication: "Ruby Weekly"
issue: 566
published_at: "2021-08-19"
canonical_url: "https://rubyweekly.com/issues/566"
---

Plus more tutorials, projects, and a Ruby tip of the week. |        

#​566 — August 19, 2021 

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

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/vyif2ct6g8y2razsjkkn.jpg)](https://world.hey.com/dhh/modern-web-apps-without-javascript-bundling-or-transpiling-a20f2755)  

[On Modern Rails + Web Apps Without JavaScript Bundling or Transpiling](https://world.hey.com/dhh/modern-web-apps-without-javascript-bundling-or-transpiling-a20f2755) — DHH has explained what approaches the next iteration of JavaScript in Rails will take and import maps have a huge role to play. The goal is to, eventually, not need a bundler like Webpacker and just pull in the ES6 modules you need. 

David Heinemeier Hansson (DHH)    

“Unless new evidence comes to bear that refutes the basic tenets of this analysis, Rails 7.0 will aim to give you a default setup based on import maps, and leave the Webpacker approach as an optional alternative.” 

___
David Heinemeier Hansson    

▶[An 'Alpha Preview' of Modern JavaScript in Rails 7 Without Webpack](https://www.youtube.com/watch?v=PtxZvFnL2i0) — As tends to be David’s way (from way back when the _build a blog system in 15 minutes_ video boosted Rails’ initial popularity) he’s recorded a practical screencast showing off his latest thoughts. 

David Heinemeier Hansson (DHH)   [![\](https://copm.s3.amazonaws.com/c7effbef.png)](https://www.appsignal.com/tour/uptime-monitoring?utm_source=boostedproductfeature&utm_medium=ruby-weekly&utm_campaign=uptime-monitoring&utm_content=primary) 

[Uptime Monitoring Is Now Available in AppSignal](https://www.appsignal.com/tour/uptime-monitoring?utm_source=boostedproductfeature&utm_medium=ruby-weekly&utm_campaign=uptime-monitoring&utm_content=primary) — Uptime monitoring is the first line of defense against downtime. Ping your apps every minute from 4 locations around the world and receive alerts when something is down. Now you'll know about downtime before your users do. 

AppSignal sponsor   

[TTY::Option: A Declarative Command-Line Arguments Parser](https://github.com/piotrmurach/tty-option) — An extensive parser that covers just about every CLI scenario one could imagine. 

Piotr Murach   

▶[How to Debug a Rails App](https://www.youtube.com/watch?v=MJSZ3WcgHeE) — A nice 30-minute screencast gently introducing you to the practicalities of debugging Rails apps from the basics through to using external tools and gems to help. 

Phil Smy   

**QUICK BITS:** 

- [Natalie](https://natalie-lang.org/) is a work-in-progress Ruby implementation itself written in Ruby (but which compiles code to C++). [GitHub repo](https://github.com/seven1m/natalie).
- [RubyGems 3.2.26](https://blog.rubygems.org/2021/08/17/3.2.26-released.html) has been released.
- [Imba](https://imba.io/) is a Ruby-_inspired_ (it reminds me more of CoffeeScript, though) language aimed at front-end development which compiles to JavaScript.
- In Rails 7 you'll be able to [specify jobs to be retried indefinitely](https://blog.saeloun.com/2021/08/18/rails-7-retry-failed-jobs-indefinitely).     

Jobs  

[Backend Engineer | Remote Within CET (-2/+2 Hours) | Full-Time](https://jobs.lever.co/qonto/284b8162-5293-4ad7-a9e6-4ad26ce0c516?lever-origin=applied&lever-source%5B%5D=Cooperpress) — Join us as a Backend Engineer to create the finance solution all businesses love - Tailor made remote policy or relocation package. 
Qonto   

[Senior FullStack Ruby Engineer](https://apply.workable.com/global-app-testing/j/069DA3930E/) — We build the testing platform used by companies like Google or Facebook and 50k professional testers around the world. 
Global App Testing   

[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  

[One Row, Many Threads: How to Avoid Database Duplicates in Rails Apps](https://evilmartians.com/chronicles/one-row-many-threads-how-to-avoid-database-duplicates-in-rails-applications) — A primer on avoiding duplicates in database tables that back multi-threaded Rails applications, with practical code examples. 

Dmitry Tsepelev   

[Demystifying Rails Autoloading](https://kyrofa.com/posts/demystifying-rails-autoloading/) — Kyle starts with plain, old Ruby `require` and makes a quick visit to Bundler before explaining this Rails magic. 

Kyle Fazzari   

[Crunchy Bridge: Fully Managed Cloud Postgres](https://www.crunchydata.com/products/crunchy-bridge/?utm_source=Ruby+Weekly&utm_medium=newsletter&utm_campaign=Bridge&utm_id=crunchy+bridge&utm_content=8-18-21) — Crunchy Bridge users experience performance improvements, better developer workflow and seamless migration. 

Crunchy Bridge sponsor   

[`asdf` and Docker for Managing Local Development Dependencies](https://pawelurbanek.com/asdf-docker-development) — Docker provides a handy way to get more isolation between local dependencies (such as databases). `asdf` then provides a way to switch between sets of executables. 

Paweł Urbanek   

[Refactoring: In Defense of Magic](https://noelrappin.com/blog/2021/08/refactoring-part-two-in-defense-of-magic/) — Metaprogramming has a bit of a stigma to it in Ruby, but maybe we’ve overcorrected as a community? Noel thinks so as he sings the praises of metaprogramming and its benefits. 

Noel Rappin   

[Using Hotwire with Rails for a SPA Like Experience](https://www.mikewilson.dev/posts/using-hotwire-with-rails-for-a-spa-like-experience/) — It’s pretty amazing what you can do with the Hotwire gems while writing little to no JavaScript. It’s like a Turbo (ha!) boost to a SPA. 

Mike Wilson   

[A Beginner's Guide to RuboCop in Rails](https://prabinpoudel.com.np/articles/beginners-guide-to-rubocop-in-rails/) 
Prabin Poudel  

🛠 Code & Tools  

[Reek: A High Level 'Code Smell' Detector for Ruby Code](https://github.com/troessner/reek) — It’ll [detect things](https://github.com/troessner/reek/blob/master/docs/Code-Smells.md) like odd variable names, unused parameters, overuse of constants and methods, and cohesion problems. 

Timo Rößner   

[Hightop: A Shortcut for Group Count Queries](https://github.com/ankane/hightop) — Adds a `top` method to `Enumberable` so works with both plain old arrays or ActiveRecord. 

Andrew Kane   

[ActiveMedian: Median and percentiles for Active Record and More](https://github.com/ankane/active_median) — Not just for Active Record but can work with Mongoid, arrays, and hashes too. With AR it uses SQL with the main database systems for extra efficiency. 

Andrew Kane   

[Build Online Video for Ruby That Just Works](https://get.mux.com/2W5IIsa) 

Mux sponsor   

[Stitches: Create Microservices in Rails with 'Minimal Ceremony'](https://github.com/stitchfix/stitches) — You get things like API key authentication, API versioning at the router level, and some other niceties added to a Rails app. 

Stitch Fix Technology   

[punks.starter: Algorithmically Generate Your Own Curated Pixel Art](https://github.com/cryptopunksnotdead/punks.starter) — This is fun and the example in the README is worth the price of admission all by itself. 

CryptoPunks Not Dead   

[Store Attribute: ActiveRecord Extension Which Adds Typecasting to Store Accessors](https://github.com/palkan/store_attribute) 
Vladimir Dementyev   

[rails_respond_to_pb: Rails Middleware to Interface Controllers with Twirp](https://github.com/dudo/rails_respond_to_pb) 
Brett Dudo       

💡**Tip of the Week** 

   

## Singleton classes (briefly...) 

In the past few tips, we've covered [ancestors](https://rubyweekly.com/issues/563), [`prepend`](https://rubyweekly.com/issues/565) and [`include`](https://rubyweekly.com/issues/564), all in service of learning different ways Ruby allows us to import code into a class. There is one more way to do this, with `extend`. However, before we jump straight into learning about `extend`, we first need to understand singleton classes. 

Singleton classes are key to Ruby's object model. Let's say we have an instance of a class, and want to define a method on just that instance: 

```
class ExampleClass ; end

example = ExampleClass.new
def example.example_method
  "This is a singleton method"
end

example.example_method
=> "This is a singleton method"

Example.new.example_method
# NoMethodError (undefined method `example_method'
for #<ExampleClass:0x00007f9686858a80>)
``` 

We see that our `example` instance can have its own specially defined method, `example_method`, which won't work on other instances of `ExampleClass`. Where is `example_method` stored though? How does Ruby keep track of it? It's defined on `example`'s singleton class. 

Every Ruby object has a singleton class. This allows us to do things like the above: define methods on instances and have them work only for those instances. We also know that classes in Ruby are themselves objects - and so also have singleton classes. This is actually how class methods work under the hood! 

Class methods are really instance methods on a class' singleton class. Let's look more deeply: 

```
class ExampleClass
  def self.example_class_method
    "This is a class method"
  end
end

ExampleClass.example_class_method
=> "This is a class method"

ExampleClass.singleton_class.instance_methods(false)
=> [:example_class_method]
``` 

Singleton classes are deep enough to deserve a whole series themselves! For now though, we've learned what we need in order to properly understand how `extend` works next week. Namely, we've learned that class methods are instance methods on the singleton class of a class.    

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

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

- Tom Dalling highlights the challenges and constraints involved in [schema library design](https://www.tomdalling.com/blog/software-design/thoughts-on-schema-library-design) in this in-depth article.
- Is there [an efficient way](https://prabinpoudel.com.np/notes/update-multiple-records-at-once-in-rails/) to update different values in multiple records in Rails? Prabin Poudel takes a look.
- Language Server Protocol (LSP) servers provide editors with all the niceties you expect from modern IDEs, but have you [ever wondered what they say to each other](http://iftheshoefritz.com/lsp/intellisense/solargraph/2021/07/24/conversation-editor-lsp.html)?
- Abeid builds three different Rails components (including one with Stimulus) that showcase [how view components can make your views more maintainable and reusable](https://dev.to/abeidahmed/advanced-viewcomponent-patterns-in-rails-2b4m).         

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
