Skip to content

Commit

Permalink
Display method arguments correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 2, 2010
1 parent be4e216 commit aa4e516
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ If you don't want to rebuild the rdoc for `gem server`, add --no-rdoc.

* N Bug Fixes
* RDoc::AnyMethod params now get saved in ri data.
* ri now displays method arguments correctly.

=== 2.5 / 2010-03-31

Expand Down
13 changes: 13 additions & 0 deletions lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ def add_alias(method)
@aliases << method
end

##
# The call_seq or the param_seq with method name, if there is no call_seq.
#
# Use this for displaying a method's argument lists.

def arglists
if @call_seq then
@call_seq
elsif @params then
"#{name}#{param_seq}"
end
end

##
# HTML id-friendly method name

Expand Down
6 changes: 6 additions & 0 deletions lib/rdoc/attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def == other
##
# Returns nil, for duck typing with RDoc::AnyMethod

def arglists
end

##
# Returns nil, for duck typing with RDoc::AnyMethod

def block_params
end

Expand Down
22 changes: 6 additions & 16 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,23 +657,13 @@ def display_method name
end
out << RDoc::Markup::Rule.new(1)

if method.call_seq then
call_seq = method.call_seq.chomp.split "\n"
call_seq = call_seq.map { |line| [' ', line, "\n"] }
out << RDoc::Markup::Verbatim.new(*call_seq.flatten)
elsif method.params then
out << RDoc::Markup::Verbatim.new(' ', method.params, "\n")
if method.arglists then
arglists = method.arglists.chomp.split "\n"
arglists = arglists.map { |line| [' ', line, "\n"] }
out << RDoc::Markup::Verbatim.new(*arglists.flatten)
out << RDoc::Markup::Rule.new(1)
end

if method.block_params then
out << RDoc::Markup::BlankLine.new if method.call_seq
params = "yields: #{method.block_params}"
out << RDoc::Markup::Verbatim.new(' ', params, "\n")
end

out << RDoc::Markup::Rule.new(1) if
method.call_seq or method.params or method.block_params

out << RDoc::Markup::BlankLine.new
out << method.comment
out << RDoc::Markup::BlankLine.new
Expand Down Expand Up @@ -795,7 +785,7 @@ def find_methods name
end

methods.each do |item|
yield(*item)
yield(*item) # :yields: store, klass, ancestor, types, method
end

self
Expand Down
20 changes: 20 additions & 0 deletions test/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

class RDocAnyMethodTest < XrefTestCase

def test_arglists
m = RDoc::AnyMethod.new nil, 'method'

assert_nil m.arglists

m.params = "(a, b)"
m.block_params = "c, d"

assert_equal "method(a, b) { |c, d| ... }", m.arglists

call_seq = <<-SEQ
method(a) { |c| ... }
method(a, b) { |c, d| ... }
SEQ

m.call_seq = call_seq.dup

assert_equal call_seq, m.arglists
end

def test_full_name
assert_equal 'C1::m', @c1.method_list.first.full_name
end
Expand Down
4 changes: 4 additions & 0 deletions test/test_rdoc_attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def setup
@a = RDoc::Attr.new nil, 'attr', 'RW', ''
end

def test_arglists
assert_nil @a.arglists
end

def test_block_params
assert_nil @a.block_params
end
Expand Down
5 changes: 2 additions & 3 deletions test/test_rdoc_ri_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ def test_display_method
assert_match %r%Foo::Bar#blah%, out
assert_match %r%blah.5%, out
assert_match %r%blah.6%, out
assert_match %r%yields: stuff%, out
end

def test_display_method_attribute
Expand Down Expand Up @@ -423,7 +422,7 @@ def test_display_method_params
@driver.display_method 'Foo::Bar#bother'
end

assert_match %r%\(things\)%, out
assert_match %r%things.*stuff%, out
end

def test_expand_class
Expand Down Expand Up @@ -775,10 +774,10 @@ def util_store

@blah = RDoc::AnyMethod.new nil, 'blah'
@blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
@blah.block_params = "stuff"

@bother = RDoc::AnyMethod.new nil, 'bother'
@bother.params = "(things)"
@bother.block_params = "stuff"

@new = RDoc::AnyMethod.new nil, 'new'
@new.singleton = true
Expand Down

0 comments on commit aa4e516

Please sign in to comment.