Question

I am creating a graphics library gem.

When creating a gem it seems that it is important to make sure that there are no conflicts with other gems or other code.

For example, extension (monkeypatch) methods are called from within my gem code.

class Array
  def sum
    inject(0.0) { |result, el| result + el }
  end

So, the solution seems to be a module.

How to create a module and ensure that there are no conflicts with other code when the gem is downloaded and used by others?

Was it helpful?

Solution

You just do it. Create a module, and use it:

 module MyLibrary
   class MyGraphicsClass
     # ...
   end
 end

This in no way helps prevent your monkey patches from stomping on other people's toes. There is no way to prevent your modification to Array from potentially breaking other people's code. The solution is to not do that. Patching fundamental parts of the standard library is a horrible practice, and a great way to make sure nobody wants to touch your gem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top