Thursday, April 30, 2009

Ruby's object.methods reflection in Scala

Update: Just found out the Scala REPL in trunk has tab completion, which does pretty much exactly this with a lot less fuss. Cool.

If you're coming from the Ruby world to learn Scala you'll learn quickly how much you miss Ruby's elegant reflection. On day 5 of my Scala adventure I took a crack at using Java's reflection APIs to do the job. I think it worked out pretty well. I'd love to hear what you think about it.

get the code here



1
2
3
4
5
//names of all methods, including super classes
namesOf(methods("Foo"))

//signatures of all methods, excluding super classes
signaturesOf(declaredMethods("Foo"))

No comments: