Created
July 27, 2009 18:47
-
-
Save wilson/156671 to your computer and use it in GitHub Desktop.
This file contains 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
words = %w(one two three lol zarglezargle one two six jambo) | |
p words.select {|word| word if (word.length > 3)..(word.length > 5) } | |
# output: | |
# ["three", "lol", "zarglezargle", "jambo"] | |
# 'one' and 'two' are skipped because they are not > 3 characters in length | |
# 'three' triggers the left side of the flip-flop condition | |
# 'lol' is selected because the left side has triggered, but not the right side | |
# 'zarglezargle' triggers the right side condition, and 'turns off' the flip-flop | |
# Because we used '..' here instead of '...' in the flip-flop, the condition returns true | |
# This code, with '...', would leave 'zarglezargle' out of the output | |
# The flip-flop is now off, so 'one', 'two', and 'six' are skipped. | |
# Finally, 'jambo' re-triggers the flip-flop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment