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

Allow methody objects to accept more Ruby.

In particular this disables shell-words so quotes and spaces are
preserved.
This commit is contained in:
Conrad Irwin 2011-10-15 00:51:56 -07:00
parent bf85c62c42
commit f72228bd1c
4 changed files with 21 additions and 7 deletions

View file

@ -7,7 +7,7 @@ class Pry
run ".ri", *args
end
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?" do |*args|
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?", :shellwords => false do |*args|
target = target()
opts = parse_options!(args, :method_object => true) do |opt|
@ -34,7 +34,7 @@ class Pry
alias_command "?", "show-doc"
command "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info." do |*args|
command "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info.", :shellwords => false do |*args|
target = target()
opts = parse_options!(args, :method_object => true) do |opt|
@ -60,7 +60,7 @@ class Pry
EOS
end
command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist" do |*args|
command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist", :shellwords => false do |*args|
require 'gist'
target = target()

View file

@ -5,7 +5,7 @@ class Pry
Introspection = Pry::CommandSet.new do
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args|
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source", :shellwords => false do |*args|
opts = parse_options!(args, :method_object => true) do |opt|
opt.banner unindent <<-USAGE
Usage: show-method [OPTIONS] [METH]
@ -198,7 +198,7 @@ class Pry
end
end
command "edit-method", "Edit a method. Type `edit-method --help` for more info." do |*args|
command "edit-method", "Edit a method. Type `edit-method --help` for more info.", :shellwords => false do |*args|
target = target()
opts = parse_options!(args, :method_object => true) do |opt|

View file

@ -20,10 +20,10 @@ class Pry
def from_str(name, target=TOPLEVEL_BINDING, options={})
if name.nil?
from_binding(target)
elsif name.to_s =~ /(\S+)\#(\S+)\Z/
elsif name.to_s =~ /(.+)\#(\S+)\Z/
context, meth_name = $1, $2
from_module(target.eval(context), meth_name)
elsif name.to_s =~ /(\S+)\.(\S+)\Z/
elsif name.to_s =~ /(.+)\.(\S+)\Z/
context, meth_name = $1, $2
from_obj(target.eval(context), meth_name)
elsif options[:instance]

View file

@ -302,6 +302,20 @@ describe "Pry::DefaultCommands::Introspection" do
$str_output = nil
end
it "should find methods even if there are spaces in the arguments" do
o = Object.new
def o.foo(*bars);
"Mr flibble"
self;
end
str_output = StringIO.new
redirect_pry_io(InputTester.new("show-method o.foo('bar', 'baz bam').foo", "exit-all"), str_output) do
binding.pry
end
str_output.string.should =~ /Mr flibble/
end
# dynamically defined method source retrieval is only supported in
# 1.9 - where Method#source_location is native
if RUBY_VERSION =~ /1.9/