I'm using a hash to store a little data needed to parse a website including URL and the specific instructions to use Nokogiri to parse the headlines of the site. However the nested Hash I used is interpreted as an Array.
webSite = { :everdoH =>
{ :url => "http://www.everardoherrera.com/" ,
:instruc=> Proc.new PageToParse.css('.contentheading').css('.contentpagetitle')}
}
If I do:
puts webSite.class
webSite.each {|aSite| puts aSite.class }
The I get this:
>> Hash
>> Array
Therefore I can't use any of the Hash indexing properties.
Any idea why I am not getting class type Hash on the nested part?
Because Hash#each, Hash#each_pair passes key-value pair (array) as parameters.
webSite = { :everdoH =>
{ :url => "http://www.everardoherrera.com/" ,
:instruc=> 'blah'
}
}
webSite.each { |aSite| p aSite }
# => [:everdoH, {:url=>"http://www.everardoherrera.com/", :instruc=>"blah"}]
Try one of followings (printing class of value, not key-value pair):
webSite.each {|aSite| puts aSite[1].class }
# => Hash
webSite.each {|key, aSite| puts aSite.class }
# => Hash
webSite.each_value {|aSite| puts aSite.class }
# => Hash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With