3 ms·
There are a lot stranger stuff hiding in Ruby. Flip-flops. Do I need to elaborate?
by yxhuvud 16y ago
There are a lot stranger stuff hiding in Ruby.
Flip-flops. Do I need to elaborate?
- avar 16y agoRuby got its flip-flop operator from Perl, which in turn got it from sed and awk. It can be really useful for keeping simple state, e.g.: # parse mail messages while (<$email>) { $in_header = 1 .. /^$/; $in_body = /^$/ .. eof; if ($in_header) { # do something } else { # in body # do something else } } And other examples at http://perldoc.perl.org/perlop.html#Range-Operators http://perldoc.perl.org/perlop.html#Range-Operators