From 377e4f918a94faf4d2a25dfe5908fe60ec6150fd Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 02:16:37 +0300 Subject: [PATCH 1/2] Resolve class comments from the absolute constant name --- lib/method_source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/method_source.rb b/lib/method_source.rb index ffd79ad..8819efa 100644 --- a/lib/method_source.rb +++ b/lib/method_source.rb @@ -152,7 +152,7 @@ def class_comment class_inst_or_module = class_inst_or_module.class end - location = class_inst_or_module.const_source_location(const_name) + location = class_inst_or_module.const_source_location("::#{const_name}") MethodSource.comment_helper(location, defined?(name) ? name : inspect) end From 68e9e99bb315943c3c040ad77a3b336916bfe9a3 Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:35:04 +0300 Subject: [PATCH 2/2] Add regression coverage for resolve class comments from the absolute constant name --- spec/method_source_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/method_source_spec.rb b/spec/method_source_spec.rb index 1927670..67898bf 100644 --- a/spec/method_source_spec.rb +++ b/spec/method_source_spec.rb @@ -1,5 +1,11 @@ require 'spec_helper' +# Documentation for the outer class. +class MethodSourceShadowedClass + MethodSourceShadowedClass = Module.new + def work; end +end + describe MethodSource do describe "source_location (testing 1.8 implementation)" do @@ -96,6 +102,11 @@ # if RUBY_VERSION =~ /1.9/ || is_rbx? describe "Lambdas and Procs" do + it "uses the absolute class name when a nested constant shadows it" do + comment = MethodSourceShadowedClass.new.method(:work).class_comment + expect(comment).to eq("# Documentation for the outer class.\n") + end + it 'should return source for proc' do expect(MyProc.source).to eq(@proc_source) end