Fixing Range#step
Update: This has been added to Rails’ active_support.
My last post got me thinking about my post a couple months ago about being annoyed that Range\#step
requires a block and returns itself.
Well, it’s Ruby. If you don’t like it, change it:
Now, before you start yelling at me for being an irresponsible programmer, may I remind you that this change and the ones in my previous post in no way change the original functionality of Range. step
raises an error if no block is given, and include?
simply returns false if a range is passed (you can’t have a Range of Ranges, so previously, a range would never include another Range).
I think I may submit a patch for ActiveSupport with these little nuggets.
update: test your code before you publish it. Code has been fixed so it really doesn’t have any adverse side-effects.