Skip to content

Instantly share code, notes, and snippets.

@RichardJordan
Created February 15, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardJordan/25d2c74d21fab2621fa92b82eeb99183 to your computer and use it in GitHub Desktop.
Save RichardJordan/25d2c74d21fab2621fa92b82eeb99183 to your computer and use it in GitHub Desktop.
Command Pattern - null listener
module RJ
module Utils
module NullListener
# allows for injection of a different class for null_listeners
#
attr_writer :null_listener_class
private
# make available a null_listener that uses the null object pattern
#
def null_listener
_null_listener_source.call
end
# creates an anonymous class based on Naught library for null listener
# - allows for dependency injection to enable swap out of class
#
def _null_listener_class
@null_listener_class ||= Naught.build
end
# proc which when called instantiates an instance of null listener class
#
def _null_listener_source
_null_listener_class.public_method(:new)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment