# Hash assignment (what's happening?)

**URL:** <https://rubytalk.org/t/hash-assignment-whats-happening/41184>\
**Category:** ruby-talk\
**Created:** [5 October 2007 14:16 UTC](https://rubytalk.org/t/hash-assignment-whats-happening/41184 "2007-10-05T14:16:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hector1](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Hector1](https://rubytalk.org/u/Hector1)\
**Post date:** [5 October 2007 14:16 UTC](https://rubytalk.org/t/hash-assignment-whats-happening/41184/1 "2007-10-05T14:16:12Z")

</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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Hector1](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Hector1](https://rubytalk.org/u/Hector1)\
**Post date:** [5 October 2007 14:17 UTC](https://rubytalk.org/t/hash-assignment-whats-happening/41184/2 "2007-10-05T14:17:54Z")

</div>

Hector Quiroz 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Dejan\_Dimic](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@Dejan\_Dimic](https://rubytalk.org/u/Dejan_Dimic)\
**Post date:** [5 October 2007 14:30 UTC](https://rubytalk.org/t/hash-assignment-whats-happening/41184/3 "2007-10-05T14:30:16Z")

</div>

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)

> **···**
>
> On Oct 5, 4:16 pm, Hector Quiroz \<hqui...@enh.org\> 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.  
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Jason\_R](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jason\_R](https://rubytalk.org/u/Jason_R)\
**Post date:** [5 October 2007 14:31 UTC](https://rubytalk.org/t/hash-assignment-whats-happening/41184/4 "2007-10-05T14:31:20Z")

</div>

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

Jason

> **···**
>
> On 10/5/07, Hector Quiroz \<hquiroz@enh.org\> 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.  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
