Created
February 15, 2019 02:52
-
-
Save RichardJordan/25d2c74d21fab2621fa92b82eeb99183 to your computer and use it in GitHub Desktop.
Command Pattern - null listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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