Created
August 25, 2014 16:41
-
-
Save danjenson/b171271726198630e245 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
ruby -e "('A'..'Z').each { |x| ('A'..x).each { |y| print y == 'E' ? 'X' : y }; puts }" |
Author
danjenson
commented
Aug 26, 2014
- Outer loop 'A'..'Z' loops from A->Z sending a character to the variable 'x' in the block.
- 'x' is used as the end point of the inner range, which is iterated over, yielding a character from A->'x' to the block as 'y'.
- The block prints 'y', but checks first to see if it equals 'E' using a ternary operator (http://stackoverflow.com/questions/4252936/how-do-i-use-the-conditional-operator-in-ruby). If the character equals 'E', it switches it with 'X', otherwise it prints the original character, 'y'.
- After each inner loop, puts prints a new line (by default).
Show off!!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment