Skip to content

Instantly share code, notes, and snippets.

@dajobe
Last active May 22, 2018 14:33
Show Gist options
  • Save dajobe/7586938 to your computer and use it in GitHub Desktop.
Save dajobe/7586938 to your computer and use it in GitHub Desktop.
Get the methods on a class / object - aka python dir()
// Inspired by http://stackoverflow.com/questions/2886446/how-to-get-methods-list-in-scala
def dir(x: AnyRef): Unit = println(x.getClass.getMethods.map(_.getName).distinct.sorted.mkString(" "))
scala> dir("")
charAt codePointAt codePointBefore codePointCount compareTo compareToIgnoreCase concat contains contentEquals copyValueOf endsWith equals equalsIgnoreCase format getBytes getChars getClass hashCode indexOf intern isEmpty lastIndexOf length matches notify notifyAll offsetByCodePoints regionMatches replace replaceAll replaceFirst split startsWith subSequence substring toCharArray toLowerCase toString toUpperCase trim valueOf wait
@jpr71
Copy link

jpr71 commented Dec 15, 2015

Hey sorry to bother, but why AnyRef instead of Any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment