Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

version 0.7.0, added pry-doc support and a few misc things.

* added pry-doc support for ruby core C methods, (show-doc and
  show-method)
* added _ex_ local for recovering last exception
* added -mj option to ls to display methods defined strictly on
  singleton class.
  • Loading branch information...
commit e1d2372e07fe5d1a08abcefc46fedc9c24ac8635 1 parent 8016fb7
@banister banister authored
View
5 CHANGELOG
@@ -1,3 +1,8 @@
+15/3/2011 version 0.7.0
+* add pry-doc support with syntax highlighting for docs
+* add 'mj' option to ls (restrict to singleton methods)
+* add _ex_ local to hold last exception raised in an exception
+
6/3/2011 version 0.6.8
* add whereami command, a la the `ir_b` gem
* make whereami run at the start of every session
View
11 README.markdown
@@ -22,9 +22,14 @@ is trivial to set it to read from any object that has a `readline` method and wr
`puts` method - many other aspects of Pry are also configurable making
it a good choice for implementing custom shells.
-Pry now comes with an executable so it can be invoked at the command line.
+Pry comes with an executable so it can be invoked at the command line.
Just enter `pry` to start. A `.pryrc` file in the user's home directory will
-be loaded if it exists. Type `pry --help` at the command line for more information.
+be loaded if it exists. Type `pry --help` at the command line for more
+information.
+
+Try `gem install pry-doc` for additional documentation on Ruby Core
+methods. The additional docs are accessed through the `show-doc` and
+`show-method` commands.
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
@@ -163,10 +168,12 @@ end.
###Features:
* Pry can be invoked at any time and on any object in the running program.
+* Additional documentation and source code for Ruby Core methods are supported when the `pry-doc` gem is installed.
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
* Pry comes with syntax highlighting on by default just use the `toggle-color` command to turn it on and off.
* Use `_` to recover last result.
* Use `_pry_` to reference the Pry instance managing the current session.
+* Use `_ex_` to recover the last exception.
* Pry supports tab completion.
* Pry has multi-line support built in.
* Use `^d` (control-d) to quickly break out of a session.
View
6 TODO
@@ -1,6 +1,12 @@
+
FUTURE
* allows pipes (|) for commands
+0.7.0
+* add pry-doc support with syntax highlighting for docs
+* add 'mj' option to ls (restrict to singleton methods)
+* add _ex_ local to hold last exception raised in an exception
+
0.6.8
* add whereami command, a la the `ir_b` gem
* make .pryrc be loaded by run-time pry sessions
View
73 lib/pry/commands.rb
@@ -38,15 +38,24 @@ class Commands < CommandBase
get_method_object = lambda do |meth_name, target, options|
if options[:M]
target.eval("instance_method(:#{meth_name})")
- elsif options[:m]
+ elsif options[:m]
target.eval("method(:#{meth_name})")
- else
- begin
- target.eval("method(:#{meth_name})")
- rescue
- target.eval("instance_method(:#{meth_name})")
- end
+ else
+ begin
+ target.eval("instance_method(:#{meth_name})")
+ rescue
+ target.eval("method(:#{meth_name})")
end
+ end
+ end
+
+ make_header = lambda do |file, line, code_type|
+ header = case code_type
+ when :ruby
+ "--\nFrom #{file} @ line #{line}:\n--"
+ else
+ "--\nFrom Ruby Core (C Method):\n--"
+ end
end
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
@@ -409,7 +418,8 @@ class Commands < CommandBase
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[34m#{$1}\e[0m" : $1 }.
- gsub(/\B\+(.*)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }
+ gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
+ gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }
end
strip_leading_hash_from_ruby_comments = lambda do |comment|
@@ -423,7 +433,7 @@ class Commands < CommandBase
OptionParser.new do |opts|
opts.banner = %{Usage: show-doc [OPTIONS] [METH]
-Show the comments above method METH. Shows _method_ comments (rather than instance methods) by default.
+Show the comments above method METH. Tries instance methods first and then methods by default.
e.g show-doc hello_method
--
}
@@ -462,17 +472,22 @@ class Commands < CommandBase
end
code_type = :ruby
-
- if Pry.has_pry_doc
+ if Pry.has_pry_doc && meth.source_location.nil?
info = Pry::MethodInfo.info_for(meth)
if !info
- doc = meth.comment
- else
- doc = info.docstring
- code_type = info.source_type
+ output.puts "Cannot find docs for C method: #{meth_name}"
+ next
end
+ doc = info.docstring
+ code_type = info.source_type
else
- doc = strip_leading_hash_from_ruby_comments.call(meth.comment)
+ begin
+ doc = meth.comment
+ rescue
+ output.puts "Cannot locate source for this method: #{meth_name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
+ next
+ end
+ doc = strip_leading_hash_from_ruby_comments.call(doc)
end
doc = process_comment_markup.call(doc, code_type)
@@ -480,12 +495,7 @@ class Commands < CommandBase
file, line = meth.source_location
check_for_dynamically_defined_method.call(file)
- doc = case code_type
- when :ruby
- "--\nFrom #{file} @ line ~#{line}:\n--"
- else
- "--\nFrom Ruby Core (C Method):\n-"
- end
+ output.puts make_header.call(file, line, code_type)
output.puts doc
doc
@@ -502,7 +512,7 @@ class Commands < CommandBase
OptionParser.new do |opts|
opts.banner = %{Usage: show-method [OPTIONS] [METH]
-Show the source for method METH. Shows _method_ source (rather than instance methods) by default.
+Show the source for method METH. Tries instance methods first and then methods by default.
e.g: show-method hello_method
--
}
@@ -546,7 +556,6 @@ class Commands < CommandBase
# Try to find source for C methods using MethodInfo (if possible)
if Pry.has_pry_doc && meth.source_location.nil?
-
info = Pry::MethodInfo.info_for(meth)
if !info
output.puts "Cannot find source for C method: #{meth_name}"
@@ -554,20 +563,20 @@ class Commands < CommandBase
end
code = info.source
code = strip_comments_from_c_code.call(code)
- code_type = :c
+ code_type = info.source_type
else
- code = meth.source
+ begin
+ code = meth.source
+ rescue
+ output.puts "Cannot locate source for this method: #{meth_name}. Try `gem install pry-doc` to get access to Ruby Core documentation."
+ next
+ end
end
file, line = meth.source_location
check_for_dynamically_defined_method.call(file)
- code = case code_type
- when :ruby
- "--\nFrom #{file} @ line #{line}:\n--"
- else
- "--\nFrom Ruby Core (C Method):\n--"
- end
+ output.puts make_header.call(file, line, code_type)
if Pry.color
code = CodeRay.scan(code, code_type).term
View
2  lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.7.0pre3"
+ VERSION = "0.7.0"
end
Please sign in to comment.
Something went wrong with that request. Please try again.