[ruby-core:78162] [Ruby trunk Bug#12947] Multiline if statements behave differently than inline if statements for flip flop

From: josh.cheek@...
Date: 2016-11-15 23:31:52 UTC
List: ruby-core #78162
Issue #12947 has been reported by Josh Cheek.

----------------------------------------
Bug #12947: Multiline if statements behave differently than inline if statements for flip flop
https://bugs.ruby-lang.org/issues/12947

* Author: Josh Cheek
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
For an inline if statement, a numerical range literal in a conditional behaves like flip flop matching against `$.` 
Parsed [here](https://github.com/ruby/ruby/blob/0fe793cf9d400fdcc1f904e59d39c9b030758f42/parse.y#L1229-L1237).

```
printf first\nsecond\nthird\nforth\nfifth\n | ruby -ne 'print if 2..4'
second
third
forth
```

However when we switch it to a multiline if statement, it behaves like a regex (ie an object, so true).
Parsed [here](https://github.com/ruby/ruby/blob/0fe793cf9d400fdcc1f904e59d39c9b030758f42/parse.y#L2802-L2813).

```
$ printf first\nsecond\nthird\nforth\nfifth\n | ruby -ne 'if 2..4; print; end'
first
second
third
forth
fifth
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next