Skip to content

Instantly share code, notes, and snippets.

@pydemo
Forked from dajobe/dir.scala
Created May 22, 2018 14:33
Show Gist options
  • Save pydemo/6f48d4e5efa19630db930f8e29c1450b to your computer and use it in GitHub Desktop.
Save pydemo/6f48d4e5efa19630db930f8e29c1450b 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment