Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Created September 28, 2011 02:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/1246840 to your computer and use it in GitHub Desktop.
Save jrochkind/1246840 to your computer and use it in GitHub Desktop.
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
@xoen
Copy link

xoen commented Apr 23, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment