Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # original ApplicationController
- class ApplicationController
- def home_page?
- "original"
- end
- end
- puts ApplicationController.new.home_page?
- # => original
- # define a new implementation of home_page? outside of ApplicationController.
- # the goal is to be able to test it independently, by including it into a very simple class.
- module I18nModule
- def self.included(base)
- base.class_eval do
- def home_page?
- "i18ned"
- end
- end
- end
- # i'd prefer to do this, but that way the method ends up _behind_ the original home_page? in the method lookup list.
- # so this only works for methods that don't already exist on the class.
- #def home_page?
- # "i18ned"
- #end
- end
- class ApplicationController
- include I18nModule
- end
- puts ApplicationController.new.home_page?
- # => i18ned
Add Comment
Please, Sign In to add comment