# Is there another method like .next?

**URL:** <https://www.ruby-forum.com/t/is-there-another-method-like-next/153681>\
**Category:** Ruby\
**Created:** [November 20, 2008, 2:45am UTC](https://www.ruby-forum.com/t/is-there-another-method-like-next/153681 "2008-11-20T02:45:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_WSRyder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@Michael\_WSRyder](https://www.ruby-forum.com/u/Michael_WSRyder)\
**Post date:** [November 20, 2008, 2:45am UTC](https://www.ruby-forum.com/t/is-there-another-method-like-next/153681/1 "2008-11-20T02:45:31Z")

</div>

I was looking for a way to iterate through the ascii values and was  
trying to get it to not go from “9” to “10” or “Z” to “AA”. Evidently  
the string method .next always returns digits for digits and letters for  
letters. I could do something like:

a = “9”  
b = “”  
b \<\< a[0].next =\> “[”

but this seems overly complicated. I have to initialize b or Ruby  
complains of an undefined local variable or method and other methods of  
string assignment return “91”.

---

<div class="post-metadata">

**Author:** ![Michael\_WSRyder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@Michael\_WSRyder](https://www.ruby-forum.com/u/Michael_WSRyder)\
**Post date:** [November 20, 2008, 4:49am UTC](https://www.ruby-forum.com/t/is-there-another-method-like-next/153681/2 "2008-11-20T04:49:33Z")

</div>

On Wed, Nov 19, 2008 at 7:41 PM, Michael W. Ryder  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I was looking for a way to iterate through the ascii values

For classic printables…

(32…128).map {|int| int.chr}

You then have an array which you can #join if you want.

Todd

---

<div class="post-metadata">

**Author:** ![Michael\_WSRyder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@Michael\_WSRyder](https://www.ruby-forum.com/u/Michael_WSRyder)\
**Post date:** [November 20, 2008, 5:25am UTC](https://www.ruby-forum.com/t/is-there-another-method-like-next/153681/3 "2008-11-20T05:25:48Z")

</div>

Todd B. wrote:

> On Wed, Nov 19, 2008 at 7:41 PM, Michael W. Ryder  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I was looking for a way to iterate through the ascii values
> 
> For classic printables…
> 
> (32…128).map {|int| int.chr}

I think this should be (32…127).map as 128 is the not printable.  
I had forgotten about .chr. This allows me to do b = a[0].next.chr and  
get the desired result. This is a little more than I expected but a lot  
simpler than my first attempt. Thanks for the pointer.

> You then have an array which you can #join if you want.

---

<div class="post-metadata">

**Author:** ![Michael\_WSRyder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@Michael\_WSRyder](https://www.ruby-forum.com/u/Michael_WSRyder)\
**Post date:** [November 20, 2008, 5:49am UTC](https://www.ruby-forum.com/t/is-there-another-method-like-next/153681/4 "2008-11-20T05:49:46Z")

</div>

On Wed, Nov 19, 2008 at 10:21 PM, Michael W. Ryder  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> I think this should be (32…127).map as 128 is the not printable.

Thanks for the correction 🙂 Actually, it’s the 127 that’s not  
printable, but who’s counting.

Todd
