Skip to content

Commit 2e0336e

Browse files
itaratoandrykonchin
authored andcommitted
Add Module#undefined_instance_methods
1 parent b6c229a commit 2e0336e

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Compatibility:
2929
* Add `Module#refinements` (#3039, @itarato).
3030
* Add `Refinement#refined_class` (#3039, @itarato).
3131
* Add `rb_hash_new_capa` function (#3039, @itarato).
32+
* Add `Module#undefined_instance_methods` (#3039, @itarato).
3233

3334
Performance:
3435

spec/tags/truffle/methods_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ fails:Public methods on UnboundMethod should include protected?
115115
fails:Public methods on UnboundMethod should include public?
116116
fails:Public methods on String should not include bytesplice
117117
fails:Public methods on Module should not include refinements
118+
fails:Public methods on Module should not include undefined_instance_methods

spec/truffleruby.next-specs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ spec/ruby/core/module/refinements_spec.rb
3434
spec/ruby/core/refinement/refined_class_spec.rb
3535
spec/ruby/core/module/used_refinements_spec.rb
3636
spec/ruby/optional/capi/hash_spec.rb
37+
spec/ruby/core/module/undefined_instance_methods_spec.rb

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,4 +2355,22 @@ protected Object doClass(RubyClass rubyClass) {
23552355
return rubyClass.isSingleton;
23562356
}
23572357
}
2358+
2359+
@CoreMethod(names = "undefined_instance_methods")
2360+
public abstract static class UndefinedInstanceMethodsNode extends CoreMethodArrayArgumentsNode {
2361+
2362+
@Specialization
2363+
@TruffleBoundary
2364+
protected RubyArray undefinedInstanceMethods(RubyModule module) {
2365+
List<RubySymbol> methodNames = new ArrayList<>();
2366+
2367+
for (InternalMethod methodEntry : module.fields.getMethods()) {
2368+
if (methodEntry != null && methodEntry.isUndefined()) {
2369+
methodNames.add(getLanguage().getSymbol(methodEntry.getName()));
2370+
}
2371+
}
2372+
2373+
return createArray(methodNames.toArray());
2374+
}
2375+
}
23582376
}

test/mri/tests/ruby/test_module.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,15 @@ def test_public_instance_methods
955955
assert_equal([:bClass1], BClass.public_instance_methods(false))
956956
end
957957

958+
def test_undefined_instance_methods
959+
assert_equal([], AClass.undefined_instance_methods)
960+
assert_equal([], BClass.undefined_instance_methods)
961+
c = Class.new(AClass) {undef aClass}
962+
assert_equal([:aClass], c.undefined_instance_methods)
963+
c = Class.new(c)
964+
assert_equal([], c.undefined_instance_methods)
965+
end
966+
958967
def test_s_public
959968
o = (c = Class.new(AClass)).new
960969
assert_raise(NoMethodError, /private method/) {o.aClass1}

0 commit comments

Comments
 (0)