Created
July 17, 2012 20:26
-
-
Save practicingruby/3131824 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts 'Hello, and welcome to seventh grade English.' | |
| puts 'My name is Mrs. Crabbage. And your name is...?' | |
| name = gets.chomp | |
| # instead of name = 'jana' or 'Jana' do this... | |
| if name == 'jana' || name == 'Jana' | |
| puts 'Oh, YOU again. Please take a seat.' | |
| end | |
| # we usually use || instead of or, because it works | |
| # better in situations where we might otherwise need | |
| # parenthesis to make things work correctly. Same goes | |
| # for and vs. &&. Explaination: | |
| # http://www.themomorohoax.com/2008/12/08/and-vs-amperand-in-ruby | |
| # NOTE: once you learn regexp, you'll probably want to replace | |
| # the code above with something like this | |
| # if name[^/[Jj]ana]$/] | |
| # .... | |
| # end | |
| if name == name.capitalize | |
| # Using double quotes allows you to interpolate variables | |
| # using #{}, as shown below | |
| puts "Please take a seat #{name}." | |
| else | |
| # also, using double quotes makes it so you do not need | |
| # to escape ' | |
| puts "Don't you know how to capitalize your own name?" | |
| reply = gets.chomp | |
| # by nesting this with the else clause, it will | |
| # only be run when names are NOT capitalized | |
| if reply.downcase == 'yes' | |
| puts 'Well, then... sit down.' | |
| else | |
| puts 'Get out of my classroom!' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment