# Hash assignment (what's happening?)

**URL:** <https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443>\
**Category:** Ruby\
**Created:** [October 5, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443 "2007-10-05T16:16:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 5, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443/1 "2007-10-05T16:16:08Z")

</div>

From within irb, I’m creating a hash and populating it with the  
following data.

irb(main):007:0\> {:QHector =\> 1967, :WKelly =\> 2551, :ECron =\> 0220,  
:VLaura =\> 4003, :LWalter =\> 1188}

Why is the value for the ‘:ECron’ coming back as 144 instead of 0220?

=\> {:ECron=\>144, :VLaura=\>4003, :LWalter=\>1188, :QHector=\>1967,  
:WKelly=\>2551}  
irb(main):008:0\>

Thanks for your help in advance.

---

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 5, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443/2 "2007-10-05T16:17:54Z")

</div>

Hector Q. wrote:

> From within irb, I’m creating a hash and populating it with the  
> following data.
> 
> irb(main):007:0\> {:QHector =\> 1967, :WKelly =\> 2551, :ECron =\> 0220,  
> :VLaura =\> 4003, :LWalter =\> 1188}
> 
> Why is the value for the ‘:ECron’ coming back as 144 instead of 0220?
> 
> =\> {:ECron=\>144, :VLaura=\>4003, :LWalter=\>1188, :QHector=\>1967,  
> :WKelly=\>2551}  
> irb(main):008:0\>
> 
> Thanks for your help in advance.

Oops, the number is being interpreted by ruby as an Octal! Duh.

hq

---

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 5, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443/3 "2007-10-05T16:31:15Z")

</div>

On Oct 5, 4:16 pm, Hector Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):008:0\>
> 
> ## Thanks for your help in advance.
> 
> Posted viahttp://www.ruby-forum.com/.

I think this could help 🙂  
[http://blog.wordaligned.org/articles/2006/08/12/octal-literals](http://blog.wordaligned.org/articles/2006/08/12/octal-literals)

---

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 5, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/hash-assignment-whats-happening/116443/4 "2007-10-05T16:33:39Z")

</div>

Prefixing a ‘0’ to a number makes it octal. Either make it a string or  
don’t  
add the 0.

Jason
