Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > What the...? Hash does not have a key it really should have!

Reply
Thread Tools

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

 
 
Joshua Muheim
Guest
Posts: n/a
 
      08-10-2007
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/.

 
Reply With Quote
 
 
 
 
Stefano Crocco
Guest
Posts: n/a
 
      08-10-2007
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

 
Reply With Quote
 
 
 
 
dblack@rubypal.com
Guest
Posts: n/a
 
      08-10-2007
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)

 
Reply With Quote
 
Harold Hausman
Guest
Posts: n/a
 
      08-10-2007
On 8/10/07, Joshua Muheim <(E-Mail Removed)> 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

 
Reply With Quote
 
Joshua Muheim
Guest
Posts: n/a
 
      08-10-2007
I'm really a genius... thanks good it's weekend now =)

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

 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      08-11-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
In 'HashMap.put', "if (e.hash == hash && eq(k, e.key))" ? Red Orchid Java 3 01-30-2006 07:04 PM
Hash#eql? and Hash key testing Joel VanderWerf Ruby 4 12-04-2004 02:11 PM



Advertisments