added signature to stat and show-doc commands in ruby 1.8; added source file output to stat command
This commit is contained in:
parent
3ba8374b36
commit
3c1db5ac2f
|
@ -21,6 +21,7 @@
|
|||
* got rid of Pry.active_instance, Pry.last_exception and friends.
|
||||
* also special locals now shared among bindings in a pry instance (i.e _ex_ (and friends) re-injected into new binding entered with 'cd')
|
||||
* added third parameter to prompts, the pry instance itself (_pry) see https://github.com/pry/pry/issues/233 for why it's important
|
||||
* cd behaviour when no args performs the same as `cd /`
|
||||
|
||||
*/7/2011 version 0.9.3
|
||||
* cat --ex (cats 5 lines above and below line in file where exception was raised)
|
||||
|
|
|
@ -43,10 +43,8 @@ class Pry
|
|||
doc = process_comment_markup(doc, code_type)
|
||||
output.puts make_header(meth, code_type, doc)
|
||||
output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
|
||||
if meth.respond_to?(:parameters)
|
||||
output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
|
||||
output.puts
|
||||
end
|
||||
render_output(opts.flood?, false, doc)
|
||||
doc
|
||||
end
|
||||
|
@ -91,11 +89,9 @@ class Pry
|
|||
output.puts "Visibility: " + method_visibility(meth).to_s
|
||||
output.puts "Type: " + (meth.is_a?(Method) ? "Bound" : "Unbound")
|
||||
output.puts "Arity: " + meth.arity.to_s
|
||||
|
||||
if meth.respond_to?(:parameters)
|
||||
output.puts "Method Signature: " + signature_for(meth)
|
||||
end
|
||||
|
||||
output.puts "Source location: " + (meth.source_location ? meth.source_location.join(":") : "Not found.")
|
||||
end
|
||||
|
||||
command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist" do |*args|
|
||||
|
@ -147,19 +143,26 @@ class Pry
|
|||
end
|
||||
|
||||
helpers do
|
||||
def signature_for(meth)
|
||||
param_strings = []
|
||||
meth.parameters.each do |kind, name|
|
||||
case kind
|
||||
when :req
|
||||
param_strings << name
|
||||
when :opt
|
||||
param_strings << "#{name}=?"
|
||||
when :rest
|
||||
param_strings << "*#{name}"
|
||||
|
||||
# paraphrased from awesome_print gem
|
||||
def signature_for(method)
|
||||
if method.respond_to?(:parameters)
|
||||
|
||||
args = method.parameters.inject([]) do |arr, (type, name)|
|
||||
name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
|
||||
arr << case type
|
||||
when :req then name.to_s
|
||||
when :opt, :rest then "*#{name}"
|
||||
when :block then "&#{name}"
|
||||
else '?'
|
||||
end
|
||||
end
|
||||
"#{meth.name}(#{param_strings.join(", ")})"
|
||||
else
|
||||
args = (1..method.arity.abs).map { |i| "arg#{i}" }
|
||||
args[-1] = "*#{args[-1]}" if method.arity < 0
|
||||
end
|
||||
|
||||
"#{method.name}(#{args.join(', ')})"
|
||||
end
|
||||
|
||||
def method_visibility(meth)
|
||||
|
|
Loading…
Reference in New Issue