문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top