JRuby Java Introspection Method

Is there any way from JRuby to infiltrate a Java object and learn its Java-land methods? As if http://github.com/oggy/looksee provides, but for Java. Or how

(someobject).methods - 1.methods

It would be nice to just take a look at what the Java object provides against the APIDoc.

+3
source share
2 answers

Looksee corrects the interpreter, so it only works on MRI and YARV, and not on JRuby, XRuby, IronRuby, Ruby.NET, Rubinius, tinyrb, RubyGoLightly, MacRuby, HotRuby, BlueRuby, Cardinal, MagLev, SmallRuby, Red Sun and all other implementations .

So, if you want to install HotSpot, I'm sure you can crack the Java equivalent :-)

, :

require 'java'
java.lang.String.public_instance_methods.sort.reject {|m| m =~ /[_?!=~<>]/ }
# => [:bytes, :charAt, :class, :clone, :codePointAt, :codePointBefore, 
# => :codePointCount, :com, :compareTo, :compareToIgnoreCase, :concat, 
# => :contains, :contentEquals, :display, :dup, :empty, :endsWith, :equals, 
# => :equalsIgnoreCase, :extend, :finalize, :freeze, :getBytes, :getChars, 
# => :getClass, :hash, :hashCode, :id, :indexOf, :initialize, :inspect, :intern, 
# => :isEmpty, :java, :javax, :lastIndexOf, :length, :matches, :method, 
# => :methods, :notify, :notifyAll, :offsetByCodePoints, :org, :regionMatches, 
# => :replace, :replaceAll, :replaceFirst, :send, :split, :startsWith, 
# => :subSequence, :substring, :synchronized, :taint, :tap, :toCharArray, 
# => :toLowerCase, :toString, :toUpperCase, :trim, :trust, :type, :untaint, 
# => :untrust, :wait]

, JRuby Java Ruby , Java, Ruby , plain Java, , Ruby .

+6

Java , Java:

java.lang.String.java_class.declared_instance_methods

Class.getDeclaredMethods() Java Java::JavaMethod Java .

+6

Source: https://habr.com/ru/post/1748064/


All Articles