Skip to content

Instantly share code, notes, and snippets.

@jbodah
Created March 17, 2016 17:41
Show Gist options
  • Save jbodah/2647d8c9a50bd602b983 to your computer and use it in GitHub Desktop.
Save jbodah/2647d8c9a50bd602b983 to your computer and use it in GitHub Desktop.
simple callbacks mixin
# To use, simply define @__callbacks as a hash where the keys are events
# and the values respond to #call (e.g. lambdas, procs, methods)
#
# This implementation assumes you only have one callback per event, but
# you could use an array instead if you wanted
module SimpleCallbacks
def run_callback(type, *args)
@__callbacks[type].call(*args) if @__callbacks.has_key?(type)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment