Skip to content

Commit cf6f7c7

Browse files
authored
Merge pull request #243 from znz/redefined-methods-section
クラスページに「再定義されたメソッド」セクションを追加する
2 parents 33e97ad + e5b9932 commit cf6f7c7

9 files changed

Lines changed: 80 additions & 4 deletions

File tree

data/bitclust/catalog/ja_JP.UTF-8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Private Instance Methods
8484
privateメソッド
8585
Protected Instance Methods
8686
protectedメソッド
87+
Redefined Methods
88+
再定義されたメソッド
8789
Private Singleton Methods
8890
private特異メソッド
8991
Required Libraries

data/bitclust/template.epub/class

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
[_('Private Instance Methods'), ents.private_instance_methods ],
6060
[_('Protected Instance Methods'),ents.protected_instance_methods ],
6161
[_('Module Functions'), ents.module_functions ],
62+
[_('Redefined Methods'), ents.redefined ],
6263
[_('Constants'), ents.constants ],
6364
[_('Special Variables'), ents.special_variables ,'$']] %>
6465
<%= headline(_("Index")) %>

data/bitclust/template.lillia/class

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
[_('Module Functions'), ents.module_functions ],
6464
[_('Constants'), ents.constants ],
6565
[_('Special Variables'), ents.special_variables ],
66+
[_('Redefined Methods'), ents.redefined ],
6667
[_('Added Methods'), ents.added ] ]\
6768
.each do |label, entries|
6869
unless entries.empty? %>

data/bitclust/template.offline/class

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
[_('Private Instance Methods'), ents.private_instance_methods ],
123123
[_('Protected Instance Methods'),ents.protected_instance_methods ],
124124
[_('Module Functions'), ents.module_functions ],
125+
[_('Redefined Methods'), ents.redefined ],
125126
[_('Undefined Methods for Explanation'), ents.nomethod ],
126127
[_('Constants'), ents.constants ],
127128
[_('Special Variables'), ents.special_variables ,'$']] %>
@@ -148,8 +149,8 @@
148149

149150
<%
150151
_myself, *ancestors = @entry.ancestors.reject { |c| %w[Object Kernel BasicObject].include?(c.name) }
151-
displayed_instance_methods = Set.new(ents.instance_methods.flat_map(&:names))
152-
displayed_singleton_methods = Set.new(ents.singleton_methods.flat_map(&:names))
152+
displayed_instance_methods = Set.new((ents.instance_methods + ents.redefined.select(&:instance_method?)).flat_map(&:names))
153+
displayed_singleton_methods = Set.new((ents.singleton_methods + ents.redefined.select(&:singleton_method?)).flat_map(&:names))
153154
undefined_methods = @entry.partitioned_entries.undefined
154155
undefined_instance_methods = undefined_methods.select(&:instance_method?)
155156
undefined_singleton_methods = undefined_methods.select(&:singleton_method?)

data/bitclust/template/class

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,41 @@
114114
</code></p>
115115
<% end %>
116116

117+
<%
118+
[[_('Redefined Methods'), ents.redefined]]\
119+
.each do |label, entries|
120+
unless entries.empty? %>
121+
<%= headline(label) %>
122+
<table class="entries methods">
123+
<tr>
124+
<th><%= _('Signature') %></th>
125+
<th><%= _('Description') %></th>
126+
<th><%= _('Library') %></th>
127+
</tr>
128+
<%
129+
headline_push
130+
entries.each do |m|
131+
foreach_method_chunk(m.source) do |sigs, src| %>
132+
<tr>
133+
<td class="signature">
134+
<a href="<%=h method_url(m.spec_string) %>"><code>
135+
<%= sigs.map {|sig| h(sig.friendly_string) }.join("<br>") %>
136+
</code></a>
137+
</td>
138+
<td class="description"><%= compile_rd(src) %></td>
139+
<td class="library"><%= library_link(m.library.name) %></td>
140+
</tr>
141+
<%
142+
end
143+
end
144+
headline_pop
145+
%>
146+
</table>
147+
<%
148+
end
149+
end
150+
%>
151+
117152
<%
118153
[[_('Added Methods'), ents.added]]\
119154
.each do |label, entries|

lib/bitclust/classentry.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def add_method(m)
257257
:instance_methods, :private_instance_methods, :protected_instance_methods,
258258
:module_functions,
259259
:constants, :special_variables,
260+
:redefined,
260261
:added, :undefined, :nomethod)
261262

262263
def partitioned_entries(level = 0)
@@ -268,19 +269,21 @@ def partitioned_entries(level = 0)
268269
# @type var mf: Array[MethodEntry]
269270
# @type var c: Array[MethodEntry]
270271
# @type var v: Array[MethodEntry]
272+
# @type var redefined: Array[MethodEntry]
271273
# @type var added: Array[MethodEntry]
272274
# @type var undefined: Array[MethodEntry]
273275
# @type var nomethod: Array[MethodEntry]
274276
s = []; spv = []
275277
i = []; ipv = []; ipt = []
276278
mf = []
277279
c = []; v = []
280+
redefined = []
278281
added = []
279282
undefined = []
280283
nomethod = []
281284
entries(level).sort_by(&:name).each do |m|
282285
case m.kind
283-
when :defined, :redefined
286+
when :defined
284287
case m.type
285288
when :singleton_method
286289
(m.public? ? s : spv).push m
@@ -297,6 +300,8 @@ def partitioned_entries(level = 0)
297300
else
298301
raise "must not happen: m.type=#{m.type.inspect} (#{m.inspect})"
299302
end
303+
when :redefined
304+
redefined.push m
300305
when :added
301306
added.push m
302307
when :undefined
@@ -306,7 +311,7 @@ def partitioned_entries(level = 0)
306311
end
307312
end
308313
# steep:ignore:start
309-
Parts.new(s,spv, i,ipv,ipt, mf, c, v, added, undefined, nomethod)
314+
Parts.new(s,spv, i,ipv,ipt, mf, c, v, redefined, added, undefined, nomethod)
310315
# steep:ignore:end
311316
end
312317

sig/bitclust/classentry.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ module BitClust
9898
attr_accessor module_functions: Array[MethodEntry]
9999
attr_accessor constants: Array[MethodEntry]
100100
attr_accessor special_variables: Array[MethodEntry]
101+
attr_accessor redefined: Array[MethodEntry]
101102
attr_accessor added: Array[MethodEntry]
102103
attr_accessor undefined: Array[MethodEntry]
103104
attr_accessor nomethod: Array[MethodEntry]
@@ -106,6 +107,7 @@ module BitClust
106107
Array[MethodEntry] instance_methods, Array[MethodEntry] private_instance_methods, Array[MethodEntry] protected_instance_methods,
107108
Array[MethodEntry] module_functions,
108109
Array[MethodEntry] constants, Array[MethodEntry] special_variables,
110+
Array[MethodEntry] redefined,
109111
Array[MethodEntry] added, Array[MethodEntry] undefined, Array[MethodEntry] nomethod) -> void
110112
end
111113

test/test_class_screen.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class TestClassScreen < Test::Unit::TestCase
3939
--- explanatory_method
4040
{: nomethod}
4141
説明のために記載しているメソッドです。
42+
43+
= redefine Sub
44+
== Instance Methods
45+
--- redefined_instance_method
46+
redefined instance method
4247
HERE
4348

4449
def setup
@@ -93,4 +98,9 @@ def test_ancestor_instance_methods_include_modules
9398
assert_include(@html, 'Mixinから継承しているメソッド')
9499
assert_include(@html, 'mixin_instance_method')
95100
end
101+
102+
def test_redefined_method_is_listed_in_its_own_section
103+
assert_include(@html, '再定義されたメソッド')
104+
assert_include(@html, 'redefined_instance_method')
105+
end
96106
end

test/test_entry.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ def test_nomethod_is_partitioned_separately
163163
assert_equal([], parts.instance_methods.map(&:name))
164164
end
165165

166+
def test_redefined_is_partitioned_separately
167+
klass = parse_class(<<HERE)
168+
= class Hoge
169+
== Instance Methods
170+
--- bar
171+
172+
説明です。
173+
174+
= redefine Hoge
175+
== Instance Methods
176+
--- baz
177+
178+
再定義の説明です。
179+
HERE
180+
parts = klass.partitioned_entries
181+
assert_equal(['baz'], parts.redefined.map(&:name))
182+
assert_equal(['bar'], parts.instance_methods.map(&:name))
183+
end
184+
166185
def test_description_skips_leading_metadata_paragraph
167186
klass = parse_class(<<HERE)
168187
= class Hoge

0 commit comments

Comments
 (0)