Created
December 6, 2008 20:07
-
-
Save nrk/32946 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
handlers := Map clone | |
handlers atPut("reset", method( | |
"reset" | |
)) | |
handlers atPut("compile", method(fun_source, | |
Compiler messageForString(fun_source) doInContext(self) | |
)) | |
handlers atPut("add", method(a, b, | |
a + b | |
)) | |
handleCommand := method(cmd, | |
handlers hasKey(cmd) ifTrue( | |
return handlers at(cmd) performWithArgList("call", call evalArgs slice(1)) | |
) ifFalse( | |
return "unknown command" | |
) | |
) | |
handleCommand("reset") println | |
handleCommand("test") println | |
handleCommand("add", 2, 2) println | |
handleCommand("compile", "method(arg, \"The Answer is: #{arg}\" interpolate println)") call(42) | |
/* *** OUTPUT *** | |
reset | |
unknown command | |
4 | |
The Answer is: 42 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment