Home

Awesome

Robe Build Status MELPA

Robe is a code assistance tool that uses a Ruby REPL subprocess with your application or gem code loaded, to provide information about loaded classes and modules, and where each method is defined.

Generally, you'll want to start with M-x inf-ruby-console-auto or with M-x robe-start (which will offer to call the former function as well if there is no Ruby console running). Some interactive commands provided by Robe will also offer to launch it first.

The exceptions are code completion and eldoc, which only work if the server is already running. To launch it, type M-x robe-start.

As you change the code in your project, you'll want to update the running process. To load the current file, type <kbd>C-c C-l</kbd> (ruby-load-file), see inf-ruby for more commands. When you're working on a Rails project, you can type <kbd>C-c C-k</kbd> instead to reload the whole environment at once.

Features

To see the available commands, type <kbd>M-x describe-package RET robe RET</kbd>.

Details

When performing one of the commands defined here, we either need to narrow the method name at point down to a specific method in a specific module, or enumerate the possible method names or constants allowed at point (for code completion).

To do that, we look at the contents of the buffer, and the context at point: in which method it is, of which class, and if it's in singleton class context. Then we look at the method call at point.

If the method call target is implicit (there's no target or the method is super), or the call target is obvious (Foo.new, self.foo), then we first try to look for the definition in the inheritance hierarchy of the target class. Otherwise, or if the initial search yields no result, scan all defined classes and modules.

Depending on the command, if the result is ambiguous, you're either prompted to resolve the ambiguity manually, or the results are merged together.

Install

Set up MELPA if you haven't already, then type <kbd>M-x package-install RET robe RET</kbd>.

In the init file:

(add-hook 'ruby-mode-hook 'robe-mode)
(add-hook 'ruby-ts-mode-hook 'robe-mode)

or

(global-robe-mode)

Dependencies

The alternative to the last two items is to configure the app not to use the Pry shell (at least when inside Emacs) while still keeping pry available for loading.

Note that if your project is using Bundler, all dependencies have to be in the Gemfile.

Completion

company-mode (screenshot):

(eval-after-load 'company
  '(push 'company-robe company-backends))

Built-in completion (triggered with <kbd>C-M-i</kbd>) is also supported, no extra setup required.

Both of the above work only when the connection to the Ruby subprocess has been established. To do that, either use one of the core Robe commands, or type <kbd>M-x robe-start</kbd>.

Integration with rvm.el

rvm.el may not have activated the correct project Ruby before robe-start runs.

Either manually run <kbd>M-x rvm-activate-corresponding-ruby</kbd> before starting Robe, or advise inf-ruby-console-auto to activate rvm automatically.

(advice-add 'inf-ruby-console-auto :before #'rvm-activate-corresponding-ruby)

Compatibility

Notes

TODO

Copying

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GNU Emacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.