Issue #5400 has been updated by Joey Zhou.


Magnus Holm wrote:
> Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?

I disagree. The flip-flop syntax is obscure, but very useful, especially in text manipulation.

For example, I want to fetch some chunks of lines :

DATA.each_line do |line|
  print line if (line =~ /begin/)..(line =~ /end/)
end

__END__
0a
1begin
2c
3end
4e
5f
6begin
7end
8i
9j

this will print:

1begin
2c
3end
6begin
7end

flip-flop syntax comes from Perl, the Perl idiom looks like "print if /begin/../end/;" or "print if 5..8;" (which means print line5 to line8).

Perl idiom is implicit, not so easy to read, Ruby idiom is a little hard to write.

I'm afraid Rudy didn't take advantage of flip-flops, I try to write in this way:

  DATA.readlines.select {|line| (line =~ /begin/)..(line =~ /end/) } # error

it seems that ruby treat (line =~ /begin/)..(line =~ /end/) as a range object, that is not what I mean.

Maybe it's difficult for the parser to distinguish the range token ".." and flip-flop token "..", how about change the token?

for example, "~~"?

  DATA.readlines.select {|line| (line =~ /begin/)~~(line =~ /end/) }


----------------------------------------
Feature #5400: Remove flip-flops in 2.0
http://redmine.ruby-lang.org/issues/5400

Author: Magnus Holm
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 2.0


Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?


-- 
http://redmine.ruby-lang.org