Ruby is an extremely flexible and rich language, and it should not be difficult to avoid code duplication.
One dirty and easy way to deal with your problem is with a route to action. In .NET, you actually route requests using the annotation method and do not use any special language features.
# API::V2 implements only special_method get '/api/v2/special_method', controller: 'API::V2', action: 'special_method'
Another, more advanced way is to use modules to implement controller actions (instance methods). You can then reuse the same module in V2 of your API and override this method that you want to change.
class API::V1 # implementaton of API::V1 include ImplV1 end class API::V2 # all the methods from V1 are available in V2 too include ImplV1 # override methods from V1 here include ImplV2 end
Finally, a much simpler but less flexible way is to directly inherit V2 from V1:
class API::V2 < API::V1 def special_method
source share