Sha256: 265535331f685827d7319e119ff16b425ac09614ebba252689e933278e50e92f

Contents?: true

Size: 1.14 KB

Versions: 24

Compression:

Stored size: 1.14 KB

Contents

direc = File.dirname(__FILE__)

require 'rubygems'
require "#{direc}/../lib/pry"

# Inherit standard command set, but tweak them by importing some and
# overriding others.
# Illustrates use of `command`, `run`, and `import_from` commands.
class MyCommands < Pry::CommandBase

  # Override ls command
  command "ls", "An unhelpful ls" do
    output.puts "No, i refuse to display any useful information."
  end

  # bring in just the status command from Pry::Commands
  import_from Pry::Commands, "status"

  # analogy to Ruby's native alias_method idiom for decorating a method
  alias_command "old_status", "status", ""
  
  # Invoke one command from within another using `run`
  command "status", "Modified status."  do |x|
    output.puts "About to show status, are you ready?"
    run "old_status", x
    output.puts "Finished showing status."
  end

  # bring in a few other commands
  import_from Pry::Commands, "quit", "show-method"
end

# Start a Pry session using the commands defined in MyCommands
# Type 'help' in Pry to get a list of the commands and their descriptions
Pry.start(TOPLEVEL_BINDING, :commands => MyCommands)

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pry-0.6.7 examples/example_command_override.rb
pry-0.6.7-i386-mswin32 examples/example_command_override.rb
pry-0.6.7-i386-mingw32 examples/example_command_override.rb
pry-0.6.7pre4 examples/example_command_override.rb
pry-0.6.7pre4-i386-mswin32 examples/example_command_override.rb
pry-0.6.7pre4-i386-mingw32 examples/example_command_override.rb
pry-0.6.6 examples/example_command_override.rb
pry-0.6.5 examples/example_command_override.rb
pry-0.6.4 examples/example_command_override.rb
pry-0.6.3 examples/example_command_override.rb
pry-0.6.2 examples/example_command_override.rb
pry-0.6.1 examples/example_command_override.rb
pry-0.6.0 examples/example_command_override.rb
pry-0.5.9 examples/example_command_override.rb
pry-0.5.8 examples/example_command_override.rb
pry-0.5.7 examples/example_command_override.rb
pry-0.5.6 examples/example_command_override.rb
pry-0.5.5 examples/example_command_override.rb
pry-0.5.4 examples/example_command_override.rb
pry-0.5.2 examples/example_command_override.rb