.. or a flip flop inherited from Perl, which received it from AWK and sed in * nix. It is very powerful, but in your specific use it is rather obscure and not a good choice for the logic you want, especially in Ruby. Use instead:
(1..10).each {|x| puts x if (3..5) === x }
What outputs:
3 4 5
However, this is extremely important when you need to extract a series of lines from a file:
File.foreach('/usr/share/dict/propernames') { |li| puts li if ($. == 5 .. $. == 7) }
What outputs:
Agatha Ahmed Ahmet
Perl allows you to use an even lowercase expression using only the line numbers of the current line (AKA $. ), But Ruby doesn't support this.
There is also the possibility of using regular expressions that behave similarly to the previous comparison:
File.foreach('/usr/share/dict/propernames') { |li| puts li if (li[/^Wa/] .. li[/^We/]) }
What outputs:
Wade Walt Walter Warren Wayne Wendell
Because the regex works, it's possible to create a complex pattern to extract strings from a file based on matches. As the first, then the second pattern, lines, is launched. If later in the file another line starts the first template, the capture will be performed again until the second template is found. This is wonderfully powerful:
File.foreach('/usr/share/dict/propernames') { |li| puts li if ( li[/^Am/] .. li[/^An/] or li[/^Wa/] .. li[/^We/] ) }
What outputs:
Amanda Amarth Amedeo Ami Amigo Amir Amos Amy Anatole Wade Walt Walter Warren Wayne Wendell
Or alternately, for our obscure codes of talking friends:
File.foreach('/usr/share/dict/propernames') { |li| puts li if (li[/^(?:Am|Wa)/] .. li[/^(?:An|We)/]) }