Part 2. Navigating to a Declaration or Implementation
On this page:
- Preparing an example
- Navigating to declaration
- Navigating to implementation
- Navigating with gutter icons
Preparing an example
Do the following:
- Add directory
Animals
under your project root (Alt+Insert | ). - Create the following Ruby files (Alt+Insert | ):
- Add the following code to the classes:
mammalia.rb
:class Mammalia < Object @extremities = 4 def proliferates pass end def feeds puts "Milk" end end class Marsupials < Mammalia def proliferates puts "poach" end end class Eutherians < Mammalia def proliferates puts "placenta" end end class Feline < Carnivore @extremities = 4 def colors color = "?" puts color end def sounds sound = "?" puts sound end end class Cat < Feline color = "stripes and points" sound = "miaou" puts (color,sound) end class Tiger < Feline end cat = Cat.new puts cat.colors
carnivore.rb
:class Carnivore < Mammalia def feeds puts "meat" end end
herbivore.rb
:class Herbivore < Mammalia def feeds puts "grass" end end
Navigating to declaration
Place the caret at the method feeds
of the instance of the class Cat
, and press
Ctrl+B. RubyMine jumps to the declaration of the method feeds
,
which is declared in the class Mammalia
:
Navigating to implementation
Now, place caret at the declaration of the class Mammalia
and try to find out which other
classes implement it. To do that, press Ctrl+Alt+B. You see a rather long list of
classes implementing Mammalia
:
Ok, choose whichever implementation you need (for example,
Tiger
), and press Enter. RubyMine navigates to the
selected implementation and places the caret at the class
Tiger
declaration:
Should you select, for example Carnivore
, which resides in a separate file, this file would open
in a separate editor tab.
Side note about pin
Presumably, you have already noticed the pin icon in the upper-right corner of the pop-up window. The same icon appears, for example, in the quick documentation lookup (Ctrl+Q). If you click this pin, the whole pop-up window will be "pinned", which in the case of navigation and search means that all the encountered occurrences will be presented in the Find tool window.
Navigating with gutter icons
Finally, let's look at the left gutter. You see there a number of icons with the arrows pointing up or down. What does it mean?
If you hover your mouse pointer over an icon, RubyMine will show the list of child classes or overriding methods (in case of the down arrow), or the parent classes (in case of the up arrow):
What happens, if you click an icon? If a certain class is subclassed, or a method is overridden in more than one class, RubyMine will suggest to select the desired target from the list:
After that, RubyMine jumps to the selected target, and places the caret at the class (method) declaration. If there is only one superclass/subclass, or method, then such a navigation is done silently.