Skip to content

Commit 7bf0b11

Browse files
authored
Merge pull request #590 from aycabta/is_alias_for-with-nil-singleton
Fix AnyMethod#is_alias_for for nil singleton
2 parents cfa2d31 + ba2e10f commit 7bf0b11

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/rdoc/context.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,13 @@ def find_local_symbol(symbol)
863863
# Finds a method named +name+ with singleton value +singleton+.
864864

865865
def find_method(name, singleton)
866-
@method_list.find { |m| m.name == name && m.singleton == singleton }
866+
@method_list.find { |m|
867+
if m.singleton
868+
m.name == name && m.singleton == singleton
869+
else
870+
m.name == name && !m.singleton && !singleton
871+
end
872+
}
867873
end
868874

869875
##

test/test_rdoc_any_method.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ def test_marshal_load_aliased_method
151151
assert aliased_method.display?
152152
end
153153

154+
def test_marshal_load_aliased_method_with_nil_singleton
155+
aliased_method = Marshal.load Marshal.dump(@c2_a)
156+
157+
aliased_method.store = @store
158+
aliased_method.is_alias_for = ["C2", nil, "b"]
159+
160+
assert_equal 'C2#a', aliased_method.full_name
161+
assert_equal 'C2', aliased_method.parent_name
162+
assert_equal '()', aliased_method.params
163+
assert_equal @c2_b, aliased_method.is_alias_for, 'is_alias_for'
164+
assert aliased_method.display?
165+
end
166+
154167
def test_marshal_load_class_method
155168
class_method = Marshal.load Marshal.dump(@c1.method_list.first)
156169

test/test_rdoc_context.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ def test_find_local_symbol
559559
assert_equal @c2_c3, @c2.find_local_symbol('C3')
560560
end
561561

562+
def test_find_method
563+
loaded_c2 = Marshal.load Marshal.dump @c2
564+
assert_equal @c2_a, loaded_c2.find_method('a', false)
565+
assert_equal @c2_b, loaded_c2.find_method('b', false)
566+
assert_equal @c2_a, loaded_c2.find_method('a', nil)
567+
assert_equal @c2_b, loaded_c2.find_method('b', nil)
568+
end
569+
562570
def test_find_method_named
563571
assert_equal true, @c1.find_method_named('m').singleton
564572
end

0 commit comments

Comments
 (0)