For example, when an array [-2, -1, 0, 1, 2] is given, I'd like to write
[-2, -1, 0, 1, 2].select(&.positive?)
[-2, -1, 0, 1, 2].select(&.negative?)
instead of
[-2, -1, 0, 1, 2].select { |i| i > 0 }
[-2, -1, 0, 1, 2].select { |i| i < 0 }
So I want to add Number#positive? and #negative? like Ruby.
Duplicate of #6552
IMO it's sad they were rejected.
I probably wasn't around when this was rejected, but I think it's harmless to add those two methods, and they might be a bit more descriptive than { |x| x > 0 } or &.>(0).
I'll argue against bloating stdlib API, as such use-case isn't standard, and app specific functionality should be treated differently. IMHO stdlib does provide enough mechanism to extend and shouldn't be bloated to cater all use-cases needs. Just my two cents
Most helpful comment
I probably wasn't around when this was rejected, but I think it's harmless to add those two methods, and they might be a bit more descriptive than
{ |x| x > 0 }or&.>(0).