Skip to content

Commit

Permalink
[GR-19220] Add Module#undefined_instance_methods
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3923
  • Loading branch information
andrykonchin committed Jul 28, 2023
2 parents 6554576 + 9d42b24 commit 9ff255a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Compatibility:
* Add `Refinement#refined_class` (#3039, @itarato).
* Add `rb_hash_new_capa` function (#3039, @itarato).
* Fix `Encoding::Converter#primitive_convert` and raise `FrozenError` when a destination buffer argument is frozen (@andrykonchin).
* Add `Module#undefined_instance_methods` (#3039, @itarato).

Performance:

Expand Down
1 change: 1 addition & 0 deletions spec/tags/truffle/methods_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ fails:Public methods on UnboundMethod should include protected?
fails:Public methods on UnboundMethod should include public?
fails:Public methods on String should not include bytesplice
fails:Public methods on Module should not include refinements
fails:Public methods on Module should not include undefined_instance_methods
1 change: 1 addition & 0 deletions spec/truffleruby.next-specs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec/ruby/core/sizedqueue/pop_spec.rb
spec/ruby/core/sizedqueue/shift_spec.rb

spec/ruby/core/module/refinements_spec.rb
spec/ruby/core/module/undefined_instance_methods_spec.rb
spec/ruby/core/refinement/refined_class_spec.rb
spec/ruby/core/module/used_refinements_spec.rb
spec/ruby/optional/capi/hash_spec.rb
18 changes: 18 additions & 0 deletions src/main/java/org/truffleruby/core/module/ModuleNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2356,4 +2356,22 @@ protected Object doClass(RubyClass rubyClass) {
return rubyClass.isSingleton;
}
}

@CoreMethod(names = "undefined_instance_methods")
public abstract static class UndefinedInstanceMethodsNode extends CoreMethodArrayArgumentsNode {

@Specialization
@TruffleBoundary
protected RubyArray undefinedInstanceMethods(RubyModule module) {
List<RubySymbol> methodNames = new ArrayList<>();

for (InternalMethod methodEntry : module.fields.getMethods()) {
if (methodEntry.isUndefined()) {
methodNames.add(getLanguage().getSymbol(methodEntry.getName()));
}
}

return createArray(methodNames.toArray());
}
}
}
9 changes: 9 additions & 0 deletions test/mri/tests/ruby/test_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,15 @@ def test_public_instance_methods
assert_equal([:bClass1], BClass.public_instance_methods(false))
end

def test_undefined_instance_methods
assert_equal([], AClass.undefined_instance_methods)
assert_equal([], BClass.undefined_instance_methods)
c = Class.new(AClass) {undef aClass}
assert_equal([:aClass], c.undefined_instance_methods)
c = Class.new(c)
assert_equal([], c.undefined_instance_methods)
end

def test_s_public
o = (c = Class.new(AClass)).new
assert_raise(NoMethodError, /private method/) {o.aClass1}
Expand Down

0 comments on commit 9ff255a

Please sign in to comment.