Skip to content

Instantly share code, notes, and snippets.

@mssola
Created August 2, 2013 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mssola/6138133 to your computer and use it in GitHub Desktop.
Save mssola/6138133 to your computer and use it in GitHub Desktop.
Because Ruby can flip and flop :P
# This file shows a somewhat rare feature of Ruby with the .. operator.
# It's a a perlism called "flip-flop". This feature will make it into Ruby 2.0
# but its future is uncertain (probably removed in a future Ruby 3.0 ?).
#
# More on flip-flops here: https://bugs.ruby-lang.org/issues/5400
# Prints all the lines between begin..end in the DATA section.
DATA.each_line do |line|
print line if (line =~ /begin/)..(line =~ /end/)
end
__END__
0a
1begin
2c
3end
4e
5f
6begin
7end
8i
9j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment