Skip to content

Instantly share code, notes, and snippets.

@graingert
Forked from fedesilva/repl.scala
Created December 20, 2017 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graingert/22502632fbdaecdc0f95fb151b07aba8 to your computer and use it in GitHub Desktop.
Save graingert/22502632fbdaecdc0f95fb151b07aba8 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment