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

J

Joshua Muheim

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
 
S

Stefano Crocco

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
 
D

dblack

Hi --

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)
 
H

Harold Hausman

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
 
P

Phlip

Joshua said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top