diff options
author | TSUYUSATO Kitsune <make.just.on@gmail.com> | 2023-05-24 01:16:32 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-05-23 16:16:37 +0000 |
commit | 92d6c9a7b1c3f8462e91e9b7de04b0b2012d54b3 (patch) | |
tree | 0d4602bac1eb5cb4428f08c71472aece73a77b97 /lib/irb/cmd | |
parent | 24a6609ccb21af186d1cb73258abddb82e28a9f2 (diff) | |
download | ruby-92d6c9a7b1c3f8462e91e9b7de04b0b2012d54b3.tar.gz |
[ruby/irb] Allow `show_source` for private methods
(https://github.com/ruby/irb/pull/589)
* Allow `show_source` for private methods
Fix https://github.com/ruby/irb/pull/577
* Pend tests on TruffleRuby
It seems `eval(..., __LINE__ + 1)` does not work.
Other similar tests are also pended on TruffleRuby, so I think it
is acceptable.
* Use `private_method_defined?` instead of `defined?`
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r-- | lib/irb/cmd/show_source.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb index f4925a8311..a74895b2dc 100644 --- a/lib/irb/cmd/show_source.rb +++ b/lib/irb/cmd/show_source.rb @@ -31,13 +31,14 @@ module IRB when /\A(?<owner>[A-Z]\w*(::[A-Z]\w*)*)#(?<method>[^ :.]+)\z/ # Class#method owner = eval(Regexp.last_match[:owner], irb_context.workspace.binding) method = Regexp.last_match[:method] - if owner.respond_to?(:instance_method) && owner.instance_methods.include?(method.to_sym) - file, line = owner.instance_method(method).source_location + if owner.respond_to?(:instance_method) + methods = owner.instance_methods + owner.private_instance_methods + file, line = owner.instance_method(method).source_location if methods.include?(method.to_sym) end when /\A((?<receiver>.+)(\.|::))?(?<method>[^ :.]+)\z/ # method, receiver.method, receiver::method receiver = eval(Regexp.last_match[:receiver] || 'self', irb_context.workspace.binding) method = Regexp.last_match[:method] - file, line = receiver.method(method).source_location if receiver.respond_to?(method) + file, line = receiver.method(method).source_location if receiver.respond_to?(method, true) end if file && line Source.new(file: file, first_line: line, last_line: find_end(file, line, irb_context)) |