Programming With Ruby Episode 9, Flow Control Part 2
Uploader Comments (manwithcode)
All Comments (12)
-
@Jaredplusrandomstuff Oh! That one works! Cool! Thanks for sharing this, I guess there's always more I can learn :)
-
@Jaredplusrandomstuff line formatting doesn't show up too well but you get the idea :)
-
@manwithcode I mis-spoke, the correct syntax for 'or' in a case/when statement is the following:
when '3', 'quit' puts "Goodbye!" input = 'quit'
else .....
-
@Jaredplusrandomstuff That would be cleaner! Except when I try to run it, it doesn't work... And I've never seen that syntax for a when statement, but I know there are always things I don't know, so it's certainly possible I just inputted it wrong. The odd thing though is that your when statement *does* work when input is "3", which is consistent with my knowledge of Ruby expressions, since "3" or "quit" evaluates to "3", and would only ever evaluate to "quit" if "3" magically turned into a nil
-
@manwithcode I think the cleanest way would be to do this, which matches your menu prompt and also demonstrates a simple conditional in a case.
when ('3' or 'quit') then
-
the videos are awesome
they helped a LOT
thank you : D
-
i think it's worth noting that the else statement needs to go last or there will be syntax errors.
This is a beautiful series. I have spent many hours reading until my eyes bulged. But I have learned more in one day watching your videos than I did in a week of pouring over docs. Thank you Tyler, I hope to see the saga continue!
Liquillacole 2 months ago
@Liquillacole Thanks for your kind words :)
manwithcode 2 months ago