Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # original ApplicationController
  2. class ApplicationController
  3. def home_page?
  4. "original"
  5. end
  6. end
  7.  
  8. puts ApplicationController.new.home_page?
  9. # => original
  10.  
  11. # define a new implementation of home_page? outside of ApplicationController.
  12. # the goal is to be able to test it independently, by including it into a very simple class.
  13. module I18nModule
  14. def self.included(base)
  15. base.class_eval do
  16. def home_page?
  17. "i18ned"
  18. end
  19. end
  20. end
  21. # i'd prefer to do this, but that way the method ends up _behind_ the original home_page? in the method lookup list.
  22. # so this only works for methods that don't already exist on the class.
  23. #def home_page?
  24. # "i18ned"
  25. #end
  26. end
  27.  
  28. class ApplicationController
  29. include I18nModule
  30. end
  31.  
  32. puts ApplicationController.new.home_page?
  33. # => i18ned
Add Comment
Please, Sign In to add comment