Guest User

Untitled

a guest
Feb 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. module RJ
  2. module Utils
  3. module NullListener
  4. # allows for injection of a different class for null_listeners
  5. #
  6. attr_writer :null_listener_class
  7.  
  8. private
  9.  
  10. # make available a null_listener that uses the null object pattern
  11. #
  12. def null_listener
  13. _null_listener_source.call
  14. end
  15.  
  16. # creates an anonymous class based on Naught library for null listener
  17. # - allows for dependency injection to enable swap out of class
  18. #
  19. def _null_listener_class
  20. @null_listener_class ||= Naught.build
  21. end
  22.  
  23. # proc which when called instantiates an instance of null listener class
  24. #
  25. def _null_listener_source
  26. _null_listener_class.public_method(:new)
  27. end
  28. end
  29. end
  30. end
Add Comment
Please, Sign In to add comment