# Need help understand an expression

**URL:** <https://www.ruby-forum.com/t/need-help-understand-an-expression/153900>\
**Category:** Ruby\
**Created:** [November 22, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/need-help-understand-an-expression/153900 "2008-11-22T16:39:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![buzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ee59a6/32.png) [@buzz](https://www.ruby-forum.com/u/buzz)\
**Post date:** [November 22, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/need-help-understand-an-expression/153900/1 "2008-11-22T16:39:22Z")

</div>

Hi,

Can someone explain the role of the “?” before the “x”

s = “abcdefg”  
s[0] = ?x # s == “xbcdef”

I know this will accomplish the same thing.

s[0] = ‘x’

Thanks,  
Buzz

---

<div class="post-metadata">

**Author:** ![buzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ee59a6/32.png) [@buzz](https://www.ruby-forum.com/u/buzz)\
**Post date:** [November 22, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/need-help-understand-an-expression/153900/2 "2008-11-22T17:04:37Z")

</div>

On Sun, Nov 23, 2008 at 12:35 AM, Buzz H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> s[0] = ‘x’

sigma ~ % irb  
s = “abcdefg”

# “abcdefg”

s[0] = ?x

# 120

?x

# 120

s

# “xbcdefg”

s[0] = ‘x’

# “x”

s

# “xbcdefg”

‘x’[0]

# 120

s[0]

# 120

s[0,1]

# ‘x’

‘x’[0,1]

# ‘x’

^ manveru

---

<div class="post-metadata">

**Author:** ![buzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ee59a6/32.png) [@buzz](https://www.ruby-forum.com/u/buzz)\
**Post date:** [November 22, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/need-help-understand-an-expression/153900/3 "2008-11-22T17:14:35Z")

</div>

On Sat, Nov 22, 2008 at 9:35 AM, Buzz H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> s[0] = ‘x’

irb(main):004:0\> ?a  
=\> 97

It’s an integer value keyword.

[Programming Ruby: The Pragmatic Programmer's Guide](http://ruby-doc.org/docs/ProgrammingRuby/html/language.html) has more  
information under “Integer and Floating Point Numbers”

irb(main):005:0\> x = " "  
=\> " "  
irb(main):006:0\> x[0] = ?a  
=\> 97  
irb(main):007:0\> x  
=\> “a”

End result for the string you modify is the same because String#[]=  
with a single integer index accepts either integers or strings.

irb(main):002:0\> x[0] = ‘abc’  
=\> “abc”  
irb(main):003:0\> x  
=\> “abc”

-Michael L.

---

<div class="post-metadata">

**Author:** ![buzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ee59a6/32.png) [@buzz](https://www.ruby-forum.com/u/buzz)\
**Post date:** [November 22, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/need-help-understand-an-expression/153900/4 "2008-11-22T19:30:35Z")

</div>

Michael F.  
Michael L.

> It’s an integer value keyword.
> 
> End result for the string you modify is the same because String#[]=  
> with a single integer index accepts either integers or strings.

Thanks. I am new and not familiar with all the symbol meanings.
