addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Mad-Railers Message Board › about_koans


A former member
Post #: 3
Two questions about the Koans tonight:

(1) In about_hashes.rb, I pass test_accessing_hashes_with_fetch by adding assert_raise(IndexError,KeyError)­. I know others just added assert_raise(KeyError) and got a pass. This failed on my machine...why?

(2) What's the point of all_symbols? I see that it gives an array of all the symbols... but I'm missing the point of having it around.
Matt M.
user 13547322
Madison, WI
Post #: 1
1. KeyError is a subclass of IndexError. I believe that if you list multiple exception classes in assert_raise then you are indicating that the exception can be any of the listed exceptions. Does it work if you just do assert_raise(IndexError) ?

2. I am not aware of very many practical uses for all_symbols. I think the only time I have used it was to see if I had code that was generating a lot of extra symbols. See http://blade.nagaokau...­
Matt M.
user 13547322
Madison, WI
Post #: 2
Actually, I think I understand your issue for #1. KeyError only exists in Ruby 1.9. If you are running 1.8 then you will need to use IndexError.
Powered by mvnForum

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy