handle_message
method is one of the most fundamental controller methods in Xip. It enables you to succinctly handle messages without needing long if/else
or case
statements.handle_message
method has four different "match arms". Each arm is just key => value
pair since it's all just a hash. The keys are the match expressions
. The values are procs
that serve as the action to take if the match expression is matched.procs
can be multi-line and thus perform more than one action. In the docs for the match expressions we'll include some of those examples.procs
. You can think of them as anonymous functions from Javascript or closures. proc
is executed if the match expression is matched. That code has access to the same variables as the containing method's scope. So for example:x
will be 16
. Similarly, if the user sends the message "Refinance", the value of x
will be 17
.