Class Pry::ClassCommand
In: lib/pry/command.rb
Parent: Command

A super-class ofr Commands with structure.

This class implements the bare-minimum functionality that a command should have, namely a —help switch, and then delegates actual processing to its subclasses.

Create subclasses using {Pry::CommandSet#create_command}, and override the {options(opt)} method to set up an instance of Slop, and the {process} method to actually run the command. If necessary, you can also override {setup} which will be called before {options}, for example to require any gems your command needs to run, or to set up state.

Methods

call   help   options   process   setup   slop  

Attributes

args  [RW] 
opts  [RW] 

Public Instance methods

Set up {opts} and {args}, and then call {process}

This function will display help if necessary.

@param *String the arguments passed @return Object the return value of {process} or VOID_VALUE

Return the help generated by Slop for this command.

A function to setup Slop so it can parse the options your command expects.

NOTE: please don‘t do anything side-effecty in the main part of this method, as it may be called by Pry at any time for introspection reasons. If you need to set up default values, use {setup} instead.

@example

 def options(opt)
   opt.banner "Gists methods or classes"
   opt.on(:c, :class, "gist a class") do
     @action = :class
   end
 end

The actual body of your command should go here.

The {opts} mehod can be called to get the options that Slop has passed, and {args} gives the remaining, unparsed arguments.

The return value of this method is discarded unless the command was created with :keep_retval => true, in which case it is returned to the repl.

@example

  def process
    if opts.present?(:class)
      gist_class
    else
      gist_method
    end
  end

A function called just before {options(opt)} as part of {call}.

This function can be used to set up any context your command needs to run, for example requiring gems, or setting default values for options.

@example

  def setup;
    require 'gist'
    @action = :method
  end

Return an instance of Slop that can parse the options that this command accepts.

[Validate]