Ruby tooling
Table of Contents
Speed up Ruby #
yjit #
asdf is “The Multiple Runtime Version Manager”. Instead of rbenv
, rvm
, nvm
etc.
asdf plugin-add rust
asdf install rust latest
asdf global rust latest
RUBY_CONFIGURE_OPTS=--enable-yjit asdf install ruby 3.3.0
Alternatives are mise, spack, ubi, nix.
jemalloc #
jemalloc
is an alternative memory allocator. To install lib in Linux
apt-get install -y --no-install-recommends libjemalloc-dev libjemalloc2
or in MacOS:
brew install jemalloc
Then install ruby with jemalloc:
RUBY_CONFIGURE_OPTS=--with-jemalloc asdf install ruby 3.3.0
Bootsnap #
Bootsnap is a library that plugs into Ruby, with optional support for YAML and JSON, to optimize and cache expensive computations. See How Does This Work.
For installation see official guide.
Note: Bootsnap and Spring are orthogonal tools. While Bootsnap speeds up the loading of individual source files, Spring keeps a copy of a pre-booted Rails process on hand to completely skip parts of the boot process the next time it’s needed. The two tools work well together.
Use binstubs #
binstubs are faster than bundle exec
Note about re-installation #
If you had previously installed gems and you re-installed ruby with yjit
or jemalloc
you may need to reinstall your gems: bundle install --redownload
.
IDE and co #
VScode #
VScode is my preferred IDE (at least for now). There is also VSCodium without telemetry/tracking. There are many options for IDE, I do not see point arguing which is better.
I want to try one of GPU accelerated editors:
Ruby LSP #
Ruby LSP seems to be the most advanced language server for now. Because it is implemented as LSP it works with any editor that supports protocol, which includes VSCode, Zed, Neovim etc.
Before I was using Solargraph. Some people suggest to use both. I don’t see the point.
If you’re using VScode there is an extension for it. Note: you don’t need separate extension for Rubocop.
Other VScode extensions #
TODO
Linters #
Rubocop #
Rubocop is default choice for linter. There are a lot of good extensions, like rubocop-rails, rubocop-rspec, rubocop-performance.
Tip:
server mode rubocop --server
may improve speed of Rubocop.
Standard #
Standard is a linter & formatter built on RuboCop and provides an unconfigurable configuration to all of RuboCop’s built-in rules as well as those included in rubocop-performance. It also supports plugins built with lint_roller, like standard-rails and standard-sorbet.
It integrates with Ruby LSP, Guard, Spring.
Formatters #
Do not confuse linters (which exist to prevent footgun bugs) and formatters (which can automatically change formatting of code). Good formatter would always produce consistent result. See A prettier printer. But Rubocop and Standard can do formatting as well…
rubyfmt #
rubyfmt is interesting because it is wirtten in Rust.
Prettier for Ruby #
@prettier/plugin-ruby is a prettier plugin for the Ruby programming language and its ecosystem. I know prettier from JS world and I know this is consistent and fast tool
Others #
TODO: formatters for ERB
Type checker #
RBS #
Ruby trying to add gradual typings, like in TypeScript or Mypy, starting from v3. So far they have rbs (type signature for Ruby) and an experimental type-level Ruby interpreter typeprof ( VScode extension).
For now there is not much progress from core team, so there are opensource alternatives.
Sorbet #
Sorbet is the most widely used static type checker for Ruby today. RBS is not trying to deprecate Sorbet and its type signature format RBI. Matz and the Ruby committer team are working closely with the Sorbet team. It’s not clear though how they would merge both. VScode extension.
Steep #
Steep - gradual typing for Ruby. VScode extension.
Other #
Sord can automatically type signature files by looking at the types specified in YARD documentation comments. Claim to support all type signature formats: Sorbet’s RBI, Ruby 3/Steep’s RBS format.
Packwerk #
Packwerk is a Ruby gem used to enforce boundaries and modularize Rails applications. But before adopting it read A Packwerk Retrospective (2024).
packs is a 100% Rust implementation of packwerk, a gradual modularization platform for Ruby.
Terminal #
GPU accelerated termnials #
Except GPU accelerated editors, there are as well GPU accelerated termnials:
Utils #
If you are using terminal a lot you may as well check some modern alternatives to old favourite tools. See A list of new(ish) command line tools.
Other #
Read more: Rails UI components, Accidental complexity and closed source