Skip to content

Instantly share code, notes, and snippets.

@ReubenBond
Created December 20, 2013 12:25
Show Gist options
  • Save ReubenBond/8054104 to your computer and use it in GitHub Desktop.
Save ReubenBond/8054104 to your computer and use it in GitHub Desktop.
trait FancyTrait {
def withContext(method: => () => Unit) = {
// define some context here, like:
val sender = this.sender
// run the method which can see the context
method()
}
}
class PimpedOutClass extends FancyTrait {
def doStuff = {
withContext {
sender ! "fun message sent to a variable brought into scope by withContext"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment