Created
September 28, 2011 02:28
-
-
Save jrochkind/1246840 to your computer and use it in GitHub Desktop.
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
ruby-1.8.7-p302 :015 > module V1 | |
ruby-1.8.7-p302 :016?> class Controller | |
ruby-1.8.7-p302 :017?> def something | |
ruby-1.8.7-p302 :018?> "something" | |
ruby-1.8.7-p302 :019?> end | |
ruby-1.8.7-p302 :020?> end | |
ruby-1.8.7-p302 :021?> end | |
=> nil | |
ruby-1.8.7-p302 :022 > module V2 | |
ruby-1.8.7-p302 :023?> include V1 | |
ruby-1.8.7-p302 :024?> end | |
=> V2 | |
ruby-1.8.7-p302 :025 > V2::Controller.new.something | |
=> "something" | |
ruby-1.8.7-p302 :026 > module V2 | |
ruby-1.8.7-p302 :027?> class Controller < V1::Controller | |
ruby-1.8.7-p302 :028?> def something | |
ruby-1.8.7-p302 :029?> "else" | |
ruby-1.8.7-p302 :030?> end | |
ruby-1.8.7-p302 :031?> end | |
ruby-1.8.7-p302 :032?> end | |
=> nil | |
ruby-1.8.7-p302 :033 > V2::Controller.new.something | |
=> "else" | |
ruby-1.8.7-p302 :034 > V1::Controller.new.something | |
=> "something" | |
ruby-1.8.7-p302 :035 > V1::Controller == V2::Controller | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm in the process to write a new Rails application and the related API and I'm investingating the ways to do this. I think this approach could work very well and reduce the need for empty controllers, this way you can write the actions in the newest versions only when you break compatibility/you need to override the old behaviour.