Integer.returns_many lets you return 7.somethings

In my last post I mentioned my love of all things ActiveSupport. I’m particularly fond of how it modifies the core Integer class to easily convert between units of time:

Time.now + 7.days
=> Thu Aug 23 04:05:54 UTC 2007

Time.now – 1.month
=> Tue Jul 17 04:06:12 UTC 2007

Recap: ActiveSupport is a Rails library that modifies core Ruby classes with handy utility methods like the ones above.

Anyways, I love this syntax, and began wondering how it could be re-applied to other objects. My first idea – what about retuning an arbitrary number of objects, of any class? Wouldn’t it be neat to return 7.somethings?

It turns out you can do just that.