Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 56fd240

Browse filesBrowse files
francesmcmullineregon
authored andcommitted
Avoid error when member is present on ancestor class
Niche case - when clearing class members for new definition, avoid trying to remove members present on ancestor classes.
1 parent d7ce956 commit 56fd240
Copy full SHA for 56fd240

File tree

2 files changed

+13
-1
lines changed
Filter options

2 files changed

+13
-1
lines changed

‎lib/concurrent-ruby/concurrent/synchronization/abstract_struct.rb

Copy file name to clipboardExpand all lines: lib/concurrent-ruby/concurrent/synchronization/abstract_struct.rb
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def ns_initialize(*values)
157157
end
158158
end
159159
members.each_with_index do |member, index|
160-
clazz.send :remove_method, member if clazz.instance_methods.include? member
160+
clazz.send :remove_method, member if clazz.instance_methods(false).include? member
161161
clazz.send(:define_method, member) do
162162
@values[index]
163163
end

‎spec/concurrent/struct_shared.rb

Copy file name to clipboardExpand all lines: spec/concurrent/struct_shared.rb
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
expect(clazz.ancestors).to include described_class
2727
end
2828

29+
it 'ignores methods on ancestor classes' do
30+
ancestor = described_class.ancestors.first
31+
ancestor.class_eval { def foo; end }
32+
33+
clazz = described_class.new(:foo)
34+
expect{ described_class.const_get(clazz.to_s) }.to raise_error(NameError)
35+
expect(clazz).to be_a Class
36+
expect(clazz.ancestors).to include described_class
37+
38+
ancestor.send :remove_method, :foo
39+
end
40+
2941
it 'raises an exception when given an invalid class name' do
3042
expect{ described_class.new('lowercase') }.to raise_error(NameError)
3143
expect{ described_class.new('_') }.to raise_error(NameError)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.