1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

added new 'alias_command' and 'desc' commands to CommandBase; also made it so show_method comamnd without parameters does a show_method on __method__

This commit is contained in:
John Mair 2011-01-26 23:13:46 +13:00
parent 2ca16a0657
commit 228b95f516
6 changed files with 35 additions and 5 deletions

1
.gitignore vendored
View file

@ -4,4 +4,5 @@ Makefile
*.def
doc/
pkg/
coverage/
.yardoc/

View file

@ -37,6 +37,12 @@ task :show_version do
puts "Pry version: #{Pry::VERSION}"
end
desc "run pry"
task :pry do
require "#{direc}/lib/pry.rb"
Pry.start
end
namespace :ruby do
spec = Gem::Specification.new do |s|
apply_spec_defaults(s)

View file

@ -83,6 +83,29 @@ class Pry
imported_hash = Hash[klass.commands.select { |k, v| names.include?(k) }]
commands.merge!(imported_hash)
end
# Create an alias for a command.
# @param [String] new_command The alias name.
# @param [String] orig_command The original command name.
# @example
# class MyCommands < Pry::CommandBase
# alias_command "help_alias", "help"
def alias_command(new_command_name, orig_command_name, desc=nil)
commands[new_command_name] = commands[orig_command_name].dup
commands[new_command_name][:description] = desc if desc
end
# Set the description for a command (replacing the old
# description.)
# @param [String] name The command name.
# @param [String] description The command description.
# @example
# class MyCommands < Pry::CommandBase
# desc "help", "help description"
# end
def desc(name, description)
commands[name][:description] = description
end
end
command "help", "This menu." do |cmd|

View file

@ -76,12 +76,14 @@ class Pry
end
command "show_method", "Show sourcecode for method <methname>." do |meth_name|
doc = target.eval("method(:#{meth_name})").source
meth_name = target.eval("__method__").to_s if !meth_name
puts "blah #{meth_name.to_s}"
doc = target.eval("method(\"#{meth_name}\")").source
output.puts doc
end
command "show_imethod", "Show sourcecode for instance method <methname>." do |meth_name|
doc = target.eval("instance_method(:#{meth_name})").source
doc = target.eval("instance_method(#{meth_name})").source
output.puts doc
end

View file

@ -85,8 +85,6 @@ class Pry
def self.reset_defaults
@input = Readline
@output = $stdout
# FIXME
@commands = Pry::Commands
@prompt = DEFAULT_PROMPT
@print = DEFAULT_PRINT

View file

@ -1,3 +1,3 @@
class Pry
VERSION = "0.4.1"
VERSION = "0.4.2pre1"
end