Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created May 10, 2012 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fedesilva/2656161 to your computer and use it in GitHub Desktop.
Save fedesilva/2656161 to your computer and use it in GitHub Desktop.
Voldemort types in scala
f@omoikane:~$ scala
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :load Workshop/mine/scala-misc/voldemort.scala
Loading Workshop/mine/scala-misc/voldemort.scala...
defined module Dungeon
scala> val nemesis = Dungeon curse "fedesilva"
nemesis: java.lang.Object with ScalaObject{def shout: Unit} = I came back to haunt fedesilva
scala> nemesis.shout
fedesilvaaaaaaaaaaa!!!!!
/* You will pardon my Potteresque ignorance but where does Voldemort live? is a dungeon acceptable? */
object Dungeon {
def curse(reason:String) = {
class Voldemort(revenge:String) {
def shout { println(revenge+revenge.last.toString*10+"!"*5) }
override def toString() = "I came back to haunt "+revenge
}
new Voldemort(reason) // last expression returns
}
}
@graingert
Copy link

@fedesilva Voldemorts live in Chambers. Specifically the Chamber of Secrets

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