In Ruby 3.4 and later, how does IRB's type-based completion differ from its regexp completor, and why can it fall back under Bundler?
answer
- repl_type_completor, a bundled gem
- default :type since Ruby 3.4
- chained calls and block params
- silent fallback to RegexpCompletor
- check with irb_info
basics
~20 sSince Ruby 3.4 IRB defaults to IRB::TypeCompletor, which uses the repl_type_completor gem and RBS to infer receiver types, so chained calls and block parameters complete. If that gem cannot load, as under a Gemfile that omits it, IRB quietly uses IRB::RegexpCompletor.
solid answer
~40 sIRB has two completion engines. `IRB::RegexpCompletor` guesses from the text around the cursor, so it handles `"abc".up` but not `"Ruby".upcase.chars.s` or a block parameter. `IRB::TypeCompletor` uses the `repl_type_completor` gem, Prism and RBS signatures (plus a local `sig/` directory) to work out the receiver's type, so chained methods and `each do |s| s.up` complete. On Ruby 3.4+ the default is `:type`; `IRB_COMPLETOR`, `--type-completor`/`--regexp-completor` or `IRB.conf[:COMPLETOR]` choose explicitly. `repl_type_completor` is a bundled gem, so under `bundle exec` it is only loadable if the Gemfile lists it; when you did not ask for `:type` explicitly, IRB falls back to regexp **without a warning**. `irb_info`'s Completion line shows which engine is active.
code
ruby · 7 lines# Gemfile
source "https://rubygems.org"
group :development, :test do
gem "irb"
gem "repl_type_completor"
endgo deeper
Know that IRB completes method names with Tab and waits for end before evaluating a multi-line def.
Explain the two completors, the Ruby 3.4 default of :type, and how irb_info shows which one is active.
Diagnose degraded completion under bundle exec as a missing repl_type_completor in the Gemfile, and fix it in the development group.
Decide which developer-experience gems belong in a shared Gemfile's development group versus each engineer's global setup.
## Two completion engines IRB offers completion as you type (the `--autocomplete` default) and on Tab. Which suggestions appear depends on the **completor**: | | `IRB::RegexpCompletor` | `IRB::TypeCompletor` | |---|---|---| | How it guesses | Pattern-matches the text before the cursor, evaluating simple receivers | Analyses the code with Prism and infers types from runtime values and RBS signatures | | Chained calls like `"Ruby".upcase.chars.s` | No | Yes: suggests `Array` methods such as `sample`, `select`, `size` | | Block parameters like `each do \|s\| s.up` | No | Yes, when the element type is known | | Needs | Nothing extra | the `repl_type_completor` gem and its RBS | | Cost | Fast | Slower per keystroke | `IRB::TypeCompletor` is not a type checker: it completes the union of possible types rather than narrowing them, and it uses live values — after `a = [1]`, `a.first.` offers `Integer` methods. ## Which one you get IRB picks the engine when the session starts: 1. If `IRB.conf[:COMPLETOR]` is set — from the **`IRB_COMPLETOR`** environment variable, the **`--type-completor`** or **`--regexp-completor`** flag, or an rc file — that choice is used. 2. Otherwise, on **Ruby 3.4 or later** the default is **`:type`**; on older Rubies it is `:regexp`. 3. If `:type` was chosen but `require "repl_type_completor"` fails, IRB falls back to `RegexpCompletor`. It prints a warning **only when you asked for `:type` explicitly**; with the default, the fallback is silent. Note that IRB's own guide still shows `IRB.conf[:COMPLETOR] = :type # default is :regexp`; the source code has defaulted to `:type` since Ruby 3.4, and the code is what runs. ## Why it falls back under Bundler `repl_type_completor` ships with Ruby as a **bundled gem** (0.1.12 with Ruby 4.0.7). Outside Bundler every installed gem is loadable, so the default works. Under `bundle exec` — or any console that calls `Bundler.setup`, as framework consoles do — only gems in the lockfile can be required. If the Gemfile does not list `repl_type_completor`, the `require` fails and completion quietly degrades to regexp. The fix is a development-group entry: - `gem "repl_type_completor", group: [:development, :test]` Then `irb_info` should report `Completion: Autocomplete, ReplTypeCompletor: …` rather than `RegexpCompletor`. ## Multiline editing The same input layer, **Reline**, gives IRB multi-line editing: - IRB evaluates input only when it is **syntactically complete**. After `def parse(line)` the prompt changes from `>` to `*` and keeps collecting lines until the matching `end`. - Indentation is added automatically (`IRB.conf[:AUTO_INDENT]`, default true). - The whole multi-line block is one history entry: the up arrow brings back the full `def … end`, which you can edit in place and resubmit. - `--nomultiline` or `--singleline` switch to a single-line input method, and a `TERM=dumb` terminal gets a plain one. ## Checking and tuning - `irb_info` — shows Ruby, IRB, Reline versions and the active completion engine. - `IRB.conf[:USE_AUTOCOMPLETE] = false` or `--noautocomplete` — keep Tab completion but drop the as-you-type dialog. - A `sig/` directory or `rbs_collection.lock.yaml` in the current directory is loaded by the type completor, so a project with RBS signatures gets better suggestions for its own classes.
- Why did IRB print no warning when type completion was unavailable, but warns after you set IRB_COMPLETOR=type?IRB only reports the failed `require "repl_type_completor"` when the completor was chosen explicitly (environment variable, flag or `IRB.conf[:COMPLETOR]`). When `:type` is merely the Ruby 3.4+ default, a missing gem falls back to `RegexpCompletor` silently, so `irb_info` is how you notice.
- In IRB you type def parse(line) and press Enter. Why is nothing evaluated yet?IRB evaluates only syntactically complete input. The open `def` makes the statement incomplete, so the prompt switches to the continuation marker `*` and keeps reading lines until the matching `end`. The finished block is then evaluated as one unit and stored as one history entry.
saying these in an interview costs you the question
- IRB's default completor is still RegexpCompletor on Ruby 4.0.
- Type completion needs Steep to type-check the project first.
- A missing repl_type_completor makes IRB fail to start under Bundler.
- IRB evaluates each line as soon as Enter is pressed, even inside def.
- Type completion narrows types after is_a? checks like a static checker.