Skip to content

Conversation

@pocke
Copy link
Member

@pocke pocke commented Oct 24, 2020

Close rurema/doctree#2365

親クラスから継承している特異メソッドを、クラスのページに表示します。

Screenshot

File classの例

before
201024194601

after
201024194608

<%= headline(_("Ancestor Methods")) %>
<dl>
<% ancestors.each do |c|
undefined_methods = @entry.partitioned_entries.undefined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hanachin undefined_methodsって特異メソッドとインスタンスメソッドを区別していないように見えたのですが、合っていますか?
このPRで追加したコードだと継承したインスタンスメソッドを表示するコードをそのまま特異メソッドの方にも持ってきているので、特異メソッドとインスタンスメソッドで同名のメソッドがundefされている場合になにか壊れそうな気がしています。

その辺どうなっているのかよく理解していないので、見てもらえると助かりますー🙏

Copy link
Member

@hanachin hanachin Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このPRで追加したコードだと継承したインスタンスメソッドを表示するコードをそのまま特異メソッドの方にも持ってきているので、特異メソッドとインスタンスメソッドで同名のメソッドがundefされている場合になにか壊れそうな気がしています。

雑にundefinedされたメソッドをひとまとまりにしているので壊れますね。
現状のmasterでも特異メソッドで @undef すると同名のインスタンスメソッドが継承したメソッド一覧から消えてしまいそうな気がします。

修正方針として

  1. partitioned_entries の中でundefinedでひとまとめにせずに特異メソッドとインスタンスメソッドを分ける
  2. 雑に undefined_methods.any? の中に「m.instance_method?」なり「m.singleton_method?」のガードを追加する

のどちらかかな、と考えてます。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

特異メソッドとインスタンスメソッドで同名のメソッドがundefされている場合になにか壊れそうな気がしています。

今も壊れてそうなので2の方で直してみました
#150

singleton methodの場合こういう絞りこみが必要そうです

Suggested change
undefined_methods = @entry.partitioned_entries.undefined
undefined_methods = @entry.partitioned_entries.undefined.select(&:singleton_method?)

<%
end
end %>
<% end %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはついでの修正で、 </dl>の位置がずれていて継承したメソッドがない時にHTMLが壊れていたので修正しています

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

親クラスから継承している特異メソッドの一覧がほしい(File.readが見つけられない問題)

2 participants