How to leave a method in pry

1.2k views Asked by At

I'm using binding.pry in some Ruby code and I can't figure out how to get out of a long method that I don't want to be in.

I know n for next line and c for continue, but I can't get out of a method. I don't want to exit I just want to get out of the current method.

2

There are 2 answers

0
Uri Agassi On BEST ANSWER

According to the documentation the command you are looking for is f:

finish: Execute until current stack frame returns.

and shortcuts

if defined?(PryDebugger)
  Pry.commands.alias_command 'c', 'continue'
  Pry.commands.alias_command 's', 'step'
  Pry.commands.alias_command 'n', 'next'
  Pry.commands.alias_command 'f', 'finish'
end
0
the Tin Man On

Conveniently, pry has a command called "help". Once issued it lists a number of things pry can do, including:

  break              Set or edit a breakpoint.
  breakpoints        List defined breakpoints.
  continue           Continue program execution and end the pry session.
  finish             Execute until current stack frame returns.
  next               Execute the next line within the current stack frame.
  step               Step execution into the next line or method.

It also supports aliases to other commands, which can be convenient:

  !!!                Alias for `exit-program`
  !!@                Alias for `exit-all`
  $                  Alias for `show-source`
  ?                  Alias for `show-doc`
  @                  Alias for `whereami`
  breakpoint         Alias for `break`
  breaks             Alias for `breakpoints`
  c                  Alias for `continue`
  clipit             Alias for `gist --clip`
  f                  Alias for `finish`
  file-mode          Alias for `shell-mode`
  history            Alias for `hist`
  n                  Alias for `next`
  quit               Alias for `exit`
  quit-program       Alias for `exit-program`
  reload-method      Alias for `reload-code`
  s                  Alias for `step`
  show-method        Alias for `show-source`