core/src/main/java/org/jruby/RubyBasicObject.java
public RubyArray singleton_methods(ThreadContext context, IRubyObject[] args) {
        Ruby runtime = context.runtime;
        boolean all = (args.length == 1) ? args[0].isTrue() : true;

        RubyClass klass = metaClass;
        RubyModule origin = klass.getMethodLocation();

        Set<RubySymbol> names = (klass.isSingleton() || all) ? new HashSet<>() : Collections.EMPTY_SET;

        if (klass.isSingleton()) {
            // TODO: needs to use method_entry_i logic from MRI
            origin.getMethods().forEach((k, v) -> {
                if (v.getVisibility() != PRIVATE) names.add(runtime.newSymbol(k));
            });
            klass = klass.getSuperClass();
        }

        if (all) {
            while (klass != null && (klass.isSingleton() || klass.isIncluded())) {
                if (klass != origin) {
                    klass.getMethods().forEach((k, v) -> {
                        if (v.getVisibility() != PRIVATE) names.add(runtime.newSymbol(k));
                    });
                }
                klass = klass.getSuperClass();
            }
        }

        if (names.isEmpty()) return runtime.newEmptyArray();

        return RubyArray.newArray(runtime, names);
    }
// TODO: This is almost RubyModule#instance_methods on the metaClass.  Perhaps refactor.
This is almost RubyModule#instance_methods on the metaClass.  Perhaps refactor.
This is almost RubyModule#instance_methods on the metaClass . Perhaps refactor .
public RubyArray singleton_methods(ThreadContext context, IRubyObject[] args) {
        Ruby runtime = context.runtime;
        boolean all = (args.length == 1) ? args[0].isTrue() : true;
        RubyClass klass = metaClass;
        RubyModule origin = klass.getMethodLocation();
        Set<RubySymbol> names = (klass.isSingleton() || all) ? new HashSet<>() : Collections.EMPTY_SET;
        if (klass.isSingleton()) {
            origin.getMethods().forEach((k, v) -> {
                if (v.getVisibility() != PRIVATE) names.add(runtime.newSymbol(k));
            });
            klass = klass.getSuperClass();
        }
        if (all) {
            while (klass != null && (klass.isSingleton() || klass.isIncluded())) {
                if (klass != origin) {
                    klass.getMethods().forEach((k, v) -> {
                        if (v.getVisibility() != PRIVATE) names.add(runtime.newSymbol(k));
                    });
                }
                klass = klass.getSuperClass();
            }
        }
        if (names.isEmpty()) return runtime.newEmptyArray();
        return RubyArray.newArray(runtime, names);
    }
public RubyArray singleton_methods ( ThreadContext context , IRubyObject [ ] args ) { Ruby runtime = context . runtime ; boolean all = ( args . length == 1 ) ? args [ 0 ] . isTrue ( ) : true ; RubyClass klass = metaClass ; RubyModule origin = klass . getMethodLocation ( ) ; Set < RubySymbol > names = ( klass . isSingleton ( ) || all ) ? new HashSet < > ( ) : Collections . EMPTY_SET ; if ( klass . isSingleton ( ) ) { origin . getMethods ( ) . forEach ( ( k , v ) -> { if ( v . getVisibility ( ) != PRIVATE ) names . add ( runtime . newSymbol ( k ) ) ; } ) ; klass = klass . getSuperClass ( ) ; } if ( all ) { while ( klass != null && ( klass . isSingleton ( ) || klass . isIncluded ( ) ) ) { if ( klass != origin ) { klass . getMethods ( ) . forEach ( ( k , v ) -> { if ( v . getVisibility ( ) != PRIVATE ) names . add ( runtime . newSymbol ( k ) ) ; } ) ; } klass = klass . getSuperClass ( ) ; } } if ( names . isEmpty ( ) ) return runtime . newEmptyArray ( ) ; return RubyArray . newArray ( runtime , names ) ; }
TODO: This is almost RubyModule#instance_methods on the metaClass.
TODO : This is almost RubyModule#instance_methods on the metaClass .
// TODO: needs to use method_entry_i logic from MRI