# Why no next! method in integer class?

**URL:** <https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137>\
**Category:** Ruby\
**Created:** [July 11, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137 "2007-07-11T19:56:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradjpeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@bradjpeek](https://www.ruby-forum.com/u/bradjpeek)\
**Post date:** [July 11, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137/1 "2007-07-11T19:56:09Z")

</div>

Just curious…

The string class contains a next! method. Is there a technical  
reason for not having a next! method in the integer class, or was it  
just a language designer preference?

---

<div class="post-metadata">

**Author:** ![bradjpeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@bradjpeek](https://www.ruby-forum.com/u/bradjpeek)\
**Post date:** [July 11, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137/2 "2007-07-11T19:58:10Z")

</div>

On Jul 11, 1:55 pm, bradjpeek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just curious…
> 
> The string class contains a next! method. Is there a technical  
> reason for not having a next! method in the integer class, or was it  
> just a language designer preference?

Integer is immutable.

T.

---

<div class="post-metadata">

**Author:** ![bradjpeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@bradjpeek](https://www.ruby-forum.com/u/bradjpeek)\
**Post date:** [July 11, 2007, 8:03pm UTC](https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137/3 "2007-07-11T20:03:10Z")

</div>

Hi –

On Thu, 12 Jul 2007, bradjpeek wrote:

> Just curious…
> 
> The string class contains a next! method. Is there a technical  
> reason for not having a next! method in the integer class, or was it  
> just a language designer preference?

Probably both 🙂 The technical reason is that integers are immediate  
values, so you can’t increment them. In other words:

a = 1  
a.next!

That would mean that 1 is now 2, which would not be good. In theory  
you could change the binding of a, so that it was now bound to 2  
instead of 1; but that’s out of keeping with how these things  
generally work (e.g., with strings), which is that the object is  
mutated while the variable bindings are not affected. Doing it this  
way reinforces how objects and variables relate to each other in Ruby,  
and avoids having assignments that are masquerading as method calls.

For more on this, search the archives for discussions on ++, which is  
absent from the language for very similar reasons.

David

---

<div class="post-metadata">

**Author:** ![bradjpeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@bradjpeek](https://www.ruby-forum.com/u/bradjpeek)\
**Post date:** [July 11, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/why-no-next-method-in-integer-class/109137/4 "2007-07-11T21:51:25Z")

</div>

On 7/11/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Probably both 🙂 The technical reason is that integers are immediate  
> way reinforces how objects and variables relate to each other in Ruby,  
> and avoids having assignments that are masquerading as method calls.
> 
> For more on this, search the archives for discussions on ++, which is  
> absent from the language for very similar reasons.  
> Too kind of you David to omit my stupid RCR suggestion of  
> Integer#succ! and Integer#pred!, but it is worth searching for it as  
> things were explained very well in that thread.

BTW I am much smarter now 😉

Robert
