Module: Temple::Mixins::Dispatcher

CompiledDispatcher, ControlFlowDispatcher, CoreDispatcher, EscapeDispatcher
Included in:
Defined in:



Processing does not reach into unknown expression types by default.

Implements a compatible call-method based on the including classe’s methods.

It uses every method starting with “on” and uses the rest of the method name as prefix of the expression it will receive. So, if a dispatcher has a method named “on_x”, this method will be called with arg0,..,argN whenever an expression like [:x, arg0,..,argN ] is encountered.

This works with longer prefixes, too. For example a method named “on_y_z” will be called whenever an expression like [:y, :z, .. ] is found. Furthermore, if additionally a method named “on_y” is present, it will be called when an expression starts with :y but then does not contain with :z. This way a dispatcher can implement namespaces.


class MyAwesomeDispatch
  include Temple::Mixins::Dispatcher
  def on_awesome(thing) # keep awesome things
    return [:awesome, thing]
  def on_boring(thing) # make boring things awesome
    return [:awesome, thing+" with bacon"]
  def on(type,*args) # unknown stuff is boring too
    return [:awesome, 'just bacon']
filter =
# Boring things are converted:[:boring, 'egg']) #=> [:awesome, 'egg with bacon']
# Unknown things too:[:foo]) #=> [:awesome, 'just bacon']
# Known but not boring things won't be touched:[:awesome, 'chuck norris']) #=>[:awesome, 'chuck norris']

Method Summary

Methods included from ControlFlowDispatcher

#on_block, #on_case, #on_cond, #on_if

Methods included from EscapeDispatcher


Methods included from CoreDispatcher

#on_capture, #on_multi

Methods included from CompiledDispatcher

#call, #compile