What the...? Hash does not have a key it really should have!

Discussion in 'Ruby' started by Joshua Muheim, Aug 10, 2007.

  1. Hi all

    irb(main):001:0> conversion_classes = {
    irb(main):002:1* 'Music labels' => 'MusicLabel',
    irb(main):003:1* 'Music artists' => 'MusicArtist',
    irb(main):004:1* 'Online Shops' => 'OnlineShop',
    irb(main):005:1* 'Psy Communities' => 'PsyCommunity',
    irb(main):006:1* }
    => {"Psy Communities"=>"PsyCommunity", "Music labels"=>"MusicLabel",
    "Online Shops"=>"OnlineShop", "Music artists"=>"MusicArtist"}
    irb(main):007:0> conversion_classes.has_key? "Music Labels"
    => false

    What the heck is wrong here? I'm feeling quite blind at the moment, lol!

    Thanks
    Josh
    --
    Posted via http://www.ruby-forum.com/.
     
    Joshua Muheim, Aug 10, 2007
    #1
    1. Advertising

  2. Alle venerd=C3=AC 10 agosto 2007, Joshua Muheim ha scritto:
    > Hi all
    >
    > irb(main):001:0> conversion_classes =3D {
    > irb(main):002:1* 'Music labels' =3D> 'MusicLabel',
    > irb(main):003:1* 'Music artists' =3D> 'MusicArtist',
    > irb(main):004:1* 'Online Shops' =3D> 'OnlineShop',
    > irb(main):005:1* 'Psy Communities' =3D> 'PsyCommunity',
    > irb(main):006:1* }
    > =3D> {"Psy Communities"=3D>"PsyCommunity", "Music labels"=3D>"MusicLabel",
    > "Online Shops"=3D>"OnlineShop", "Music artists"=3D>"MusicArtist"}
    > irb(main):007:0> conversion_classes.has_key? "Music Labels"
    > =3D> false
    >
    > What the heck is wrong here? I'm feeling quite blind at the moment, lol!
    >
    > Thanks
    > Josh


    I'd say because in the hash you set the key 'Music labels', then you ask if=
    it=20
    has the key 'Music Labels'.

    Stefano
     
    Stefano Crocco, Aug 10, 2007
    #2
    1. Advertising

  3. Joshua Muheim

    Guest

    Hi --

    On Sat, 11 Aug 2007, Joshua Muheim wrote:

    > Hi all
    >
    > irb(main):001:0> conversion_classes = {
    > irb(main):002:1* 'Music labels' => 'MusicLabel',
    > irb(main):003:1* 'Music artists' => 'MusicArtist',
    > irb(main):004:1* 'Online Shops' => 'OnlineShop',
    > irb(main):005:1* 'Psy Communities' => 'PsyCommunity',
    > irb(main):006:1* }
    > => {"Psy Communities"=>"PsyCommunity", "Music labels"=>"MusicLabel",
    > "Online Shops"=>"OnlineShop", "Music artists"=>"MusicArtist"}
    > irb(main):007:0> conversion_classes.has_key? "Music Labels"
    > => false
    >
    > What the heck is wrong here? I'm feeling quite blind at the moment, lol!


    You're capitalizing "Labels".


    David

    --
    * Books:
    RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
    RUBY FOR RAILS (http://www.manning.com/black)
    * Ruby/Rails training
    & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)
     
    , Aug 10, 2007
    #3
  4. On 8/10/07, Joshua Muheim <> wrote:
    > Hi all
    >
    > irb(main):001:0> conversion_classes = {
    > irb(main):002:1* 'Music labels' => 'MusicLabel',
    > irb(main):003:1* 'Music artists' => 'MusicArtist',
    > irb(main):004:1* 'Online Shops' => 'OnlineShop',
    > irb(main):005:1* 'Psy Communities' => 'PsyCommunity',
    > irb(main):006:1* }
    > => {"Psy Communities"=>"PsyCommunity", "Music labels"=>"MusicLabel",
    > "Online Shops"=>"OnlineShop", "Music artists"=>"MusicArtist"}
    > irb(main):007:0> conversion_classes.has_key? "Music Labels"
    > => false
    >
    > What the heck is wrong here? I'm feeling quite blind at the moment, lol!
    >


    You're creating the key with a lowercase 'l' and trying to read it out
    with a capital 'L'...

    Is that the blunder?

    hth,
    -Harold
     
    Harold Hausman, Aug 10, 2007
    #4
  5. Re: What the...? Hash does not have a key it really should h

    I'm really a genius... thanks good it's weekend now =)

    Thank you guys
    --
    Posted via http://www.ruby-forum.com/.
     
    Joshua Muheim, Aug 10, 2007
    #5
  6. Joshua Muheim

    Phlip Guest

    Joshua Muheim wrote:

    > irb(main):002:1* 'Music labels' => 'MusicLabel',

    sion_classes.has_key? "Music Labels"

    > What the heck is wrong here? I'm feeling quite blind at the moment, lol!


    I lined them up (for proportional fonts). See the difference yet?

    --
    Phlip
    http://www.oreilly.com/catalog/9780596510657/
    "Test Driven Ajax (on Rails)"
    assert_xpath, assert_javascript, & assert_ajax
     
    Phlip, Aug 11, 2007
    #6
    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. Red Orchid
    Replies:
    3
    Views:
    1,054
  2. M P
    Replies:
    1
    Views:
    492
  3. rp
    Replies:
    1
    Views:
    543
    red floyd
    Nov 10, 2011
  4. Une bévue
    Replies:
    5
    Views:
    153
    Une bévue
    Aug 10, 2006
  5. Antonio Quinonez
    Replies:
    2
    Views:
    176
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page