Permalink
Browse files

it's ready for distro again

  • Loading branch information...
1 parent 90e8e29 commit d491a8ff844efe3699b8d84e91dfde80b3a01956 @rdp committed Sep 1, 2011
Showing with 191 additions and 160 deletions.
  1. +1 −0 ChangeLog
  2. +10 −5 README
  3. +3 −2 lib/ri_for/kernel_new_methods_list.rb
  4. +44 −30 lib/ri_for/method_ri.rb
  5. +132 −123 test/rubydoctest.method.rb
  6. +1 −0 test/test_ri.rb
View
@@ -0,0 +1 @@
+0.6.0: jruby support, add File.method(:delete).ri_for
View
15 README
@@ -1,11 +1,12 @@
-ri_for gem:
+the ri_for gem:
-A "run time RI for existing methods", this gem allows you to grab a method's docu at runtime--for example within an irb session. It display the method's source code/comments, ri (if available), arity, parameters, etc.
-
-It has proved quite useful, and I wouldn't do a ruby-debug session without it--you might really like it.
+A "run time documentation lookup gem", this gem allows you to grab a method's docu at runtime--for example within an irb session.
+It display the method's source code/comments, ri (if available), arity, parameters, etc.
Examples:
+given this class
+
>> class A;
def go(a); end;
end
@@ -23,7 +24,12 @@ Nothing known about A
(end ri)
=> "Parameters: go(a)"
+It has proven quite useful, and I wouldn't do a ruby-debug session without it--try it--you might like it.
+
+more examples:
+
>> File.ri_for :delete
+
sig: File.delete arity -1
appears to be a c method
Searching ri for
@@ -72,7 +78,6 @@ Parameters: assert(boolean, message = nil)
Thus, you can look at methods' source/rdocs without having to run the methods and step into them. Deftly convenient.
-
=========Installation=====
$ gem install ri_for
@@ -1,8 +1,9 @@
=begin rdoc
add method methods2 so that it returns lists that are split into two kind of [adds a marker where the inherited methods begin].
=end
+
module Kernel
- alias :methods_old :methods
+ #alias :methods_old :methods
def methods2 all = true
if all
# give some marker designating when the inherited methods start
@@ -13,7 +14,7 @@ def methods2 all = true
end
end
-class Object
+class Object # TODO add to sane [?]
def my_methods(_super=false)
_methods = (_super) ? self.class.superclass.new.methods : Object.methods
(self.methods - _methods).sort
View
@@ -1,8 +1,11 @@
+
if RUBY_VERSION < '1.9'
- require 'ruby2ruby'
- require 'parse_tree'
- gem 'rdp-arguments' # TODO why is this necessary?
- require 'arguments' # rogerdpack-arguments
+ unless RUBY_PLATFORM =~ /java/
+ require 'ruby2ruby'
+ require 'parse_tree'
+ gem 'rdp-arguments' # TODO why is this necessary?
+ require 'arguments' # rdp-arguments
+ end
end
class Object
@@ -65,32 +68,36 @@ def ri options = {}
if !(respond_to? :source_location)
# pull out names for 1.8
- begin
- klass = eval(class_name)
- # we don't call to_ruby to overcome ruby2ruby bug http://rubyforge.org/tracker/index.php?func=detail&aid=26891&group_id=1513&atid=5921
- if joiner == '#'
- raw_code = ParseTree.new.parse_tree_for_method(klass, method_name)
- else
- raw_code = ParseTree.new.parse_tree_for_method(klass.singleton_class, method_name) # singleton_class
+ unless RUBY_PLATFORM =~ /java/
+ begin
+ klass = eval(class_name)
+ # we don't call to_ruby to overcome ruby2ruby bug http://rubyforge.org/tracker/index.php?func=detail&aid=26891&group_id=1513&atid=5921
+ if joiner == '#'
+ raw_code = ParseTree.new.parse_tree_for_method(klass, method_name)
+ else
+ raw_code = ParseTree.new.parse_tree_for_method(klass.singleton_class, method_name) # singleton_class
+ end
+ doc << Ruby2Ruby.new.process(ParseTree.new.process(raw_code))
+
+ args = Arguments.names(klass, method_name, false) rescue Arguments.names(klass.singleton_class, method_name, false)
+ out = []
+ args.each{|arg_pair|
+ out << arg_pair.join(' = ')
+ } if args
+ out = out.join(', ')
+ return out if want_just_summary
+
+ param_string = "Parameters: #{method_name}(" + out + ")"
+ doc << param_string unless want_the_description_returned
+ rescue Exception => e
+ doc << "appears to be a c method"
+ puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $DEBUG
end
- doc << Ruby2Ruby.new.process(ParseTree.new.process(raw_code))
-
- args = Arguments.names(klass, method_name, false) rescue Arguments.names(klass.singleton_class, method_name, false)
- out = []
- args.each{|arg_pair|
- out << arg_pair.join(' = ')
- } if args
- out = out.join(', ')
- return out if want_just_summary
-
- param_string = "Parameters: #{method_name}(" + out + ")"
- doc << param_string unless want_the_description_returned
- rescue Exception => e
- doc << "appears to be a c method"
- puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $DEBUG
+ else
+ doc << "jruby does not allow introspection of method parameter names in 1.8.x AFAIK"
end
else
- # 1.9.x
+ # 1.9.x or REE
file, line = source_location
param_string = to_s
if file
@@ -157,9 +164,6 @@ def ri options = {}
end
-class Method; include SourceLocationDesc; end
-class UnboundMethod; include SourceLocationDesc; end
-
# TODO mixin from a separate module
class Object
@@ -181,3 +185,13 @@ def ri_for name, options = {}
end
end
end
+
+class Method;
+ include SourceLocationDesc
+ alias ri_for ri # allow for File.method(:delete).ri_for as well
+end
+
+class UnboundMethod
+ include SourceLocationDesc
+ alias ri_for ri
+end
Oops, something went wrong.

0 comments on commit d491a8f

Please sign in to comment.