Skip to content

Instantly share code, notes, and snippets.

@wilson
Created July 27, 2009 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilson/156671 to your computer and use it in GitHub Desktop.
Save wilson/156671 to your computer and use it in GitHub Desktop.
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