Project

General

Profile

Actions

Feature #17830

open

Add Integer#previous and Integer#prev

Added by rafasoares (Rafael Soares) almost 3 years ago. Updated 22 days ago.

Status:
Assigned
Target version:
-
[ruby-core:103596]

Description

I think Integer#pred is great as the inverse of #succ, but it reads a bit weird as the inverse of #next, which might be preferable for those going for a more "reads like English" approach.

On that note, #previous reads better, but it's also twice as long as #pred (or even #next). Which is why I've also added the shorthand #prev

Since Ruby strives for readability, I always thought it was weird that the team omitted this improvement.

Also, I thought about writing a gem for this, but:

  1. Do we really want to add another gem for such a simple change to every project?
  2. Monkey-patching gems feel dirty.

Finally, I want to mention that I tried looking for previous discussions on this topic, as it seems likely someone would've brought this up at some point, but was unsuccessful. Probably due to the massive amount of baggage in the core issue tracker and mailing lists, I could've missed something among the noise.

I've created a fork on GitHub (https://github.com/rafasoares/ruby/commit/05119848b1f480db2e809f964528799030cc7ebb) in order to open a PR, but decided to open this ticket as well, after reading the contributing guide more carefully.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0