[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Joshua Muheim

8/10/2007 5:49:00 PM

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

5 Answers

Stefano Crocco

8/10/2007 5:52:00 PM

0

Alle venerdì 10 agosto 2007, Joshua Muheim ha scritto:
> 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

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

Stefano

David A. Black

8/10/2007 5:53:00 PM

0

Harold Hausman

8/10/2007 5:56:00 PM

0

On 8/10/07, Joshua Muheim <forum@josh.ch> 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

Joshua Muheim

8/10/2007 6:03:00 PM

0

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

Thank you guys
--
Posted via http://www.ruby-....

Phlip

8/11/2007 2:18:00 PM

0

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/9780...
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax