views:

26

answers:

1

For some time, xml-simple gem had been working for me just fine (indirectly, through another gem).

But lately I had to install Amazon S3 gem also. Amazon guys had decided that xml-simple wasn't cool enough, so they supplied a replacement: 'faster-xml-simple'. And they also decided that everybody wants to use their code now, so they did this:

class XmlSimple # :nodoc:
  def self.xml_in(*args)
    FasterXmlSimple.xml_in *args
  end
end

But two gems largely differ in behaviour and options. And now, each time I call XmlSimple.xml_in, I go to Amazon's version.

Is there a way to stop gem A (amazon S3) from overriding methods of gem B (xml-simple)? Or make Amazon's changes seen only to Amazon's gems? E.g., when deployed on Heroku, it all works just fine.

Thanks!

+2  A: 

Ruby has open classes, which means that anybody can modify any class at any time. There's no way to prevent that. And problems like the one you are describing are exactly the reason why every manual, every tutorial, every course, every FAQ teaches not to do that.

Over the last 10 years or so, there has been talk of adding selector namespaces to Ruby 2.0, to provide lexically scoped monkey patching. More recently, matz has set his sights on classboxes. It looks very likely that Ruby 2.0 will provide classboxes to limit the scope of monkey patching, but until then, your best bet is to file a bug with the author of that library.

Jörg W Mittag