Take the 2-minute tour ×

In python:

>>> s = "abc"
>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', ...

Is there an equivalent way - i.e. dir() function - to do this with instances in the scala REPL ?

share|improve this question
Do you need something better than tab completion? –  Debilski Jan 15 '11 at 10:36
add comment

2 Answers

up vote 5 down vote accepted

When you press the tabulator-key the REPL shows you the methods which you can call on an object:

scala> val s = "abc"
s: java.lang.String = abc

scala> s.<tab>

+                     asInstanceOf          charAt
codePointAt           codePointBefore       codePointCount
compareTo             compareToIgnoreCase   concat
contains              contentEquals         endsWith
equalsIgnoreCase      getBytes              getChars
indexOf               intern                isEmpty
isInstanceOf          lastIndexOf           length
matches               offsetByCodePoints    regionMatches
replace               replaceAll            replaceFirst
split                 startsWith            subSequence
substring             toCharArray           toLowerCase
toString              toUpperCase           trim

For more information about the REPL look here.

share|improve this answer
add comment

Why tab-completion is more adequate as a help from within REPL (and it shows the parameters too, once you have written the method name!), the technical equivalent to dir is:

share|improve this answer
Not quite, since dir() will get everything, including member variables etc. –  Mike Axiak Jan 15 '11 at 16:35
@Mike That's moot, since Scala doesn't have member variables except as an implementation artifact. Everything that is usable in a Scala object is available as a method. –  Daniel C. Sobral Jan 15 '11 at 22:33
add comment

Your Answer


