# I have been looking at this little anomoly ?A =\> 65

**URL:** <https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963>\
**Category:** Ruby\
**Created:** [September 7, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963 "2008-09-07T18:27:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![victorgrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorgrey](https://www.ruby-forum.com/u/victorgrey)\
**Post date:** [September 7, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963/1 "2008-09-07T18:27:24Z")

</div>

I know that the reverse is 65.chr  
but I can find no documentation for this (aside from the above line)

And I wanted to find out more about it, so am trying things like:\>\> ?A  
=\> 65

> > hi = “Hello World”  
> > =\> “Hello World”
> 
> > hi.each {|letter| puts ?letter }  
> > SyntaxError: compile error  
> > (irb):2: syntax error, unexpected ‘}’  
> > from (irb):2
> 
> > hi.each {|letter| puts ?"#{letter}" }

^C

> > hi  
> > =\> “Hello World”
> 
> > hi.each {|letter| puts letter.? }  
> > (irb):5: warning: invalid character syntax; use ?\s  
> > SyntaxError: compile error  
> > (irb):5: syntax error, unexpected ‘?’  
> > hi.each {|letter| puts letter.? }  
> > ^  
> > from (irb):5
> 
> > hi.each {|letter| puts letter.?\s }  
> > SyntaxError: compile error  
> > (irb):6: syntax error, unexpected tINTEGER  
> > hi.each {|letter| puts letter.?\s }  
> > ^  
> > from (irb):6
> 
> > hi.each {|letter| puts letter.?\s65 }  
> > SyntaxError: compile error  
> > (irb):7: syntax error, unexpected tINTEGER  
> > hi.each {|letter| puts letter.?\s65 }  
> > ^  
> > from (irb):7

---

<div class="post-metadata">

**Author:** ![victorgrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorgrey](https://www.ruby-forum.com/u/victorgrey)\
**Post date:** [September 7, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963/2 "2008-09-07T18:51:27Z")

</div>

2008/9/7 Victor H. Goff III [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> from (irb):2
> ^
> 
> ```
> 
> hi.each {|letter| puts letter.?\s65 }  
> ^  
> from (irb):7

Try hi.each {|l| p [l, l.class]} to see why it does not work.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![victorgrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorgrey](https://www.ruby-forum.com/u/victorgrey)\
**Post date:** [September 7, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963/3 "2008-09-07T19:21:19Z")

</div>

Victor G. wrote:

> > > hi.each {|letter| puts ?letter }

You’re trying something completely wrong here. The ? is only a compiler  
thing and not an operator. If you write ?letter, it’s wrong because ?l  
can be interpreted as the code of the letter l, and the remaining etter  
is rubbish. It is not a real operator!

Apart from that, your each doesn’t split the string into letters, but  
into lines.

In Ruby 1.8 if you want the code of n-th character of your str, just  
write str[n]. It doesn’t return a single character, but its code.

In Ruby 1.9 str[n] returns n-th character in the form of a short string,  
and to get code of n-th letter, write str[n].ord.

TPR.

---

<div class="post-metadata">

**Author:** ![victorgrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorgrey](https://www.ruby-forum.com/u/victorgrey)\
**Post date:** [September 7, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963/4 "2008-09-07T19:00:14Z")

</div>

Hi,

On Sep 7, 2008, at 11:20 AM, Victor H. Goff III wrote:

> I know that the reverse is 65.chr  
> but I can find no documentation for this (aside from the above line)
> 
> And I wanted to find out more about it, so am trying things like…

Look at the documentation for String#each, String#each\_byte, and  
String#each\_char.

(For String#each\_char, make sure you require ‘jcode’ if you’re running  
Ruby 1.8.6 or lower.)

Stephen

---

<div class="post-metadata">

**Author:** ![victorgrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorgrey](https://www.ruby-forum.com/u/victorgrey)\
**Post date:** [September 7, 2008, 7:35pm UTC](https://www.ruby-forum.com/t/i-have-been-looking-at-this-little-anomoly-a-65/147963/5 "2008-09-07T19:35:24Z")

</div>

Thank you. I did understand that the ?letter was actually taking the  
‘l’  
and would have worked on it, as it should (had it not been for the  
‘etter’  
directly afterward. I just was trying to find out how to send ?  
something  
in an iterator. Bottom line: There are better ways to accomplish this.  
(Oops, on the lack of hi.split(//) or .split(/./) ) I understand that,  
and  
didn’t catch it as I was writing the IRB of something I knew was going  
to  
fail.

It was just something I came across, and hadn’t seen it used in  
anything, so  
was wondering the uses.
