Use refinements to avoid polluting number classes globally#1
Use refinements to avoid polluting number classes globally#1asehra wants to merge 1 commit intolashd:masterfrom
Conversation
|
Thanks @asehra. I don't think that the ruby version is a problem. Which project brought in the waitforit gem? I'd like to run the build using this update version before merging it. |
|
Mirage
|
|
Cheers. In addition to this change. I am thinking of putting an internal implementation of this gem inside the mirage client to drop down the number of dependencies that mirage has. I did something similar for page_magic here. What do you think? |
|
Yeah.. Sounds good. It's a simple enough implementation to have it inline.
|
Hi @lashd.
Time increments usually come with
activesupporton many projects. When a project haswaitforitalong withactivesupport, then the methods from waitforit take precedence since activesupport only declares methods likesecondsorhoursif they do not already exist. Alsoactivesupport's versions of these methods return instances ofActiveSupport::Durationand not numeric classes likeFixnum.Active support also comes with support for methods like
agoandfrom_nowthat are used commonly to represent time instances in a readable notation like5.days.ago. When used withwaitforitthis starts throwing deprecation warnings for the#agomethod since these are meant to be called onActiveSupport::Durationobjects and notFixnums.#agonotation is a very common pattern in rails and, thus, the monkeypatch in this gem leads to a ton of deprecation warning as soon as you start using Mirage in any rails project.This PR proposes using Ruby's refinements instead. That way, the time increments can be used only in places that want to use these specific refinements. Example usage can be found at lib/waitforit.rb#L31
Downside is that it will work only on ruby 2.0 and above. Earlier versions of ruby are no longer supported by ruby maintainers, so this should be ok to use.