Project

General

Profile

Actions

Bug #12947

closed

Multiline if statements behave differently than inline if statements for flip flop

Added by josh.cheek (Josh Cheek) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
[ruby-core:78162]

Description

For an inline if statement, a numerical range literal in a conditional behaves like flip flop matching against $.
Parsed here.

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.

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

Also available in: Atom PDF

Like0
Like0Like0Like0