Skip to content

Instantly share code, notes, and snippets.

@nrk
Created December 6, 2008 20:07
Show Gist options
  • Save nrk/32946 to your computer and use it in GitHub Desktop.
Save nrk/32946 to your computer and use it in GitHub Desktop.
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