Official support for ActiveSupport::Duration w/o core extensions

I’m not sure if this is the right place to ask about this, so my apologies if it is not.

I am interested in writing a Gem that takes advantage of ActiveSupport durations, but I don’t want to require using core extensions in order to use my gem. I notice that there is a ActiveSupport::Duration class that I can use, but its constructor is not documented. That makes me feel that if to rely on it is to rely on an unpublished interface.

Would it make sense for me to submit a PR to add documentation for ActiveSupport::Duration constructor to make it more of an officially supported thing?

By requiring “active_support/duration” you’re already forcing core extensions on your users. Take a look at

(And if you look at those files, they in turn require even more things from core_ext).

You might not be adding Integer#hours et al, but a bunch of other things are being added on Hash, Array, String…



Thanks for pointing that out. My question is apparently moot, then.

Is there any desire to see ActiveSupport refactored such that more of its functionality is available without having to use core extensions?

Take a look to ISO8601 gem: It have durations as well.

Thanks. I did not know about that gem. Looks very interesting (except for the use of floats for seconds ). The main reason I had been aiming for the use of ActiveSupport durations is because that makes it easier to cleanly integrate into Rails apps and the multitude of other apps that are using ActiveSupport already.

ActiveSupport::Duration uses floats for seconds too (if needed, try to execute 4.2.seconds in rails console). Few versions ago durations were (and still are) auxiliary things. Currently I’m trying to make them more self-sufficient in #16917 and #16919, but review process seems to be endless. So, I think it’s good idea to document constructor. Or may be even change it (now you should know all the parts and calculate their value in seconds to construct duration — inconvenient), but this requires consulting with someone from core team.

P.S> If you’re already using Active Support why do you ever worrying about core extensions? You have all of them already switched on in Rails app by default.

I’m hoping to target the gem for a somewhat broader audience than just my current requirement.

…but I think I’ve decided to just layer on top of ActiveSupport as is-for now, core extensions, and all.