Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def ns_initialize(*values)
end
end
members.each_with_index do |member, index|
clazz.send :remove_method, member if clazz.instance_methods.include? member
clazz.send :remove_method, member if clazz.instance_methods(false).include? member
clazz.send(:define_method, member) do
@values[index]
end
Expand Down
14 changes: 14 additions & 0 deletions spec/concurrent/struct_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
expect(clazz.ancestors).to include described_class
end

it 'ignores methods on ancestor classes' do
ancestor = described_class.ancestors.last
ancestor.class_eval { def foo(bar); end }

clazz = described_class.new(:foo)
struct = clazz.new

expect(struct).to respond_to :foo
method = struct.method(:foo)
expect(method.arity).to eq 0

ancestor.send :remove_method, :foo
end

it 'raises an exception when given an invalid class name' do
expect{ described_class.new('lowercase') }.to raise_error(NameError)
expect{ described_class.new('_') }.to raise_error(NameError)
Expand Down