From: Robert Klemme Date: 2009-05-05T16:58:11+09:00 Subject: Re: modules and classes question 2009/5/4 Marcelo Barbudas : > Hi, >> >>  class SpecializedResource < BaseResource >>    def SpecializedResource.meth >>      sr = SpecializedResource.new >>      sr.do_stuff >>    end >>  end > > This seems a little complicated, not very DRY to write this code for every > method. > > How does AWS do it? > > AWS::S3::Base.establish_connection!() > and then just: > Bucket.create('jukebox') I do not have insights into AWS beyond what can be gatherere from http://amazon.rubyforge.org/. I don't find this pattern very appealing. For something like this to work you need to resort to some form of global state (global variable, constant, class instance variable, thread local variable) which means there is potential for problems when working with multiple threads. Another issue is that it is not obvious, i.e. you do not see that there is something transported behind the scenes. I would at least refrain from placing this pattern in a library unless it is thread safe and it is sure that there will and can never be the need for more than a single connection which seems doubtful in case of AWS. My 0.02EUR. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/