mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
juts doing a quick save
This commit is contained in:
parent
537c4a6e43
commit
8f1d48236c
3 changed files with 55 additions and 4 deletions
|
@ -171,6 +171,8 @@ current directory and count the number of lines in that file with
|
||||||
|
|
||||||
### Code Browsing
|
### Code Browsing
|
||||||
|
|
||||||
|
#### show-method
|
||||||
|
|
||||||
You can browse method source code with the `show-method` command. Nearly all Ruby methods (and some C methods, with the pry-doc
|
You can browse method source code with the `show-method` command. Nearly all Ruby methods (and some C methods, with the pry-doc
|
||||||
gem) can have their source viewed. Code that is longer than a page is
|
gem) can have their source viewed. Code that is longer than a page is
|
||||||
sent through a pager (such as less), and all code is properly syntax
|
sent through a pager (such as less), and all code is properly syntax
|
||||||
|
@ -224,6 +226,46 @@ Note that we can also view C methods (from Ruby Core) using the
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### Special locals
|
||||||
|
|
||||||
|
Some commands such as `show-method`, `show-doc`, `show-command` `stat`
|
||||||
|
and `cat` update the `_file_` and `_dir_` local variables after they
|
||||||
|
run. These locals contain the full path to the file involved in the
|
||||||
|
last command as well as the directory containing that file.
|
||||||
|
|
||||||
|
You can then use these special locals in conjunction with shell
|
||||||
|
commands to do such things as change directory into the directory
|
||||||
|
containing the file, open the file in an editor, `cat` out the entire
|
||||||
|
file, and so on.
|
||||||
|
|
||||||
|
In the following example we wil use Pry to fix a bug in a method:
|
||||||
|
|
||||||
|
pry(main)> greet "john"
|
||||||
|
hello johnhow are you?=> nil
|
||||||
|
pry(main)> show-method greet
|
||||||
|
|
||||||
|
From: /Users/john/ruby/play/bug.rb @ line 2:
|
||||||
|
Number of lines: 4
|
||||||
|
|
||||||
|
def greet(name)
|
||||||
|
print "hello #{name}"
|
||||||
|
print "how are you?"
|
||||||
|
end
|
||||||
|
pry(main)> .emacsclient #{_file_}
|
||||||
|
pry(main)> load _file_
|
||||||
|
pry(main)> greet "john"
|
||||||
|
hello john
|
||||||
|
how are you?
|
||||||
|
=> nil
|
||||||
|
pry(main)> show-method greet
|
||||||
|
|
||||||
|
From: /Users/john/ruby/play/bug.rb @ line 2:
|
||||||
|
Number of lines: 4
|
||||||
|
|
||||||
|
def greet(name)
|
||||||
|
puts "hello #{name}"
|
||||||
|
puts "how are you?"
|
||||||
|
end
|
||||||
|
|
||||||
Features and limitations
|
Features and limitations
|
||||||
------------------------
|
------------------------
|
||||||
|
|
|
@ -71,12 +71,13 @@ class Pry
|
||||||
|
|
||||||
@@cd_history << Dir.pwd
|
@@cd_history << Dir.pwd
|
||||||
Dir.chdir(dest)
|
Dir.chdir(dest)
|
||||||
output.puts "=> #{dest}"
|
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
output.puts "No such directory: #{dest}"
|
output.puts "No such directory: #{dest}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
system(cmd)
|
if !system(cmd)
|
||||||
|
output.puts "Error: could not execute system command #{cmd}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tick, tock, im getting rid of this shit soon.
|
# Tick, tock, im getting rid of this shit soon.
|
||||||
|
|
|
@ -110,7 +110,14 @@ e.g: stat hello_method
|
||||||
next if opts.help?
|
next if opts.help?
|
||||||
|
|
||||||
meth_name = args.shift
|
meth_name = args.shift
|
||||||
meth_name = meth_name_from_binding(target) if !meth_name
|
if meth_name
|
||||||
|
if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context?
|
||||||
|
context, meth_name = $1, $2
|
||||||
|
target = Pry.binding_for(target.eval(context))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
meth_name = meth_name_from_binding(target)
|
||||||
|
end
|
||||||
|
|
||||||
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
||||||
output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help"
|
output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help"
|
||||||
|
@ -123,6 +130,7 @@ e.g: stat hello_method
|
||||||
|
|
||||||
output.puts make_header(meth, code_type, code)
|
output.puts make_header(meth, code_type, code)
|
||||||
output.puts bold("Method Name: ") + meth_name
|
output.puts bold("Method Name: ") + meth_name
|
||||||
|
output.puts bold("Method Owner: ") + (meth.owner.to_s ? meth.owner.to_s : "Unknown")
|
||||||
output.puts bold("Method Language: ") + code_type.to_s.capitalize
|
output.puts bold("Method Language: ") + code_type.to_s.capitalize
|
||||||
output.puts bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
output.puts bold("Method Type: ") + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
||||||
output.puts bold("Method Arity: ") + meth.arity.to_s
|
output.puts bold("Method Arity: ") + meth.arity.to_s
|
||||||
|
|
Loading…
Reference in a new issue