Created
          December 20, 2013 12:25 
        
      - 
      
 - 
        
Save ReubenBond/8054104 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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