Skip to content

Instantly share code, notes, and snippets.

Forked from fedesilva/repl.scala
Created Dec 20, 2017
What would you like to do?
Voldemort types in scala
f@omoikane:~$ scala
Welcome to Scala version (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
/* 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