Hi!

I am trying to implement a library that provides an unified way to
communicate to a server which is changing its API calls from version to
version. I plan to implement it that way:

connect.rb:

class Connect
    def self.getConn(params)
        case params[:version]
            when '4.0' then return Connect4.new(params)
            when '5.0' then return Connect5.new(params)
            else 'Version not supported.'
        end

    end
end

class Connect4
    def initialize(params)
        # Code for v4.
    end
end

class Connect5
    def initialize(params)
        # Code for v5.
    end
end
test.rb:

require 'connect'

conn = Connect.getConn(:version => '4.0')

puts conn

I think it would work, but i'm still new to ruby and there might be
issues i'm not considering. Is there any best practice to handle these
kind of 'challenge'?

-- 
Posted via http://www.ruby-forum.com/.