Hash assignment (what's happening?)

Discussion in 'Ruby' started by Hector Quiroz, Oct 5, 2007.

  1. 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/.
    Hector Quiroz, Oct 5, 2007
    #1
    1. Advertising

  2. 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/.
    Hector Quiroz, Oct 5, 2007
    #2
    1. Advertising

  3. Hector Quiroz

    dima Guest

    On Oct 5, 4:16 pm, 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.
    > --
    > Posted viahttp://www.ruby-forum.com/.


    I think this could help :)
    http://blog.wordaligned.org/articles/2006/08/12/octal-literals
    dima, Oct 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nagy
    Replies:
    36
    Views:
    998
    Terry Reedy
    Jul 20, 2006
  2. rp
    Replies:
    1
    Views:
    512
    red floyd
    Nov 10, 2011
  3. Srijayanth Sridhar
    Replies:
    19
    Views:
    608
    David A. Black
    Jul 2, 2008
  4. bernd
    Replies:
    0
    Views:
    622
    bernd
    Apr 24, 2012
  5. Replies:
    21
    Views:
    525
    Shao Miller
    Feb 17, 2013
Loading...

Share This Page