Skip to content

END not working as in MRI #3522

@jowl

Description

@jowl

BEGIN and END does not work as in MRI, at least not when used with -n and -e. The behavior differs from 1.7.23 to 9.0.4.0, but neither version does what MRI does. I'll give a few examples to try to explain what I expected, and what I got:

MRI (expected behavior):

$ ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
$ seq 2 | ruby -ne 'BEGIN { p :begin }; p :middle; END { p :end }'
:begin
:middle
:middle
:end

JRuby 9.0.4.0:

$ ruby --version
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 25.60-b23 on 1.8.0_60-b27 +jit [darwin-x86_64]
$ seq 2 | ruby -ne 'BEGIN { p :begin }; p :middle; END { p :end }'
:middle
:middle
:end
:end

JRuby 1.7.23:

$ ruby --version
jruby 1.7.23 (1.9.3p551) 2015-11-24 f496dd5 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_60-b27 +jit [darwin-x86_64]
$ seq 2 | ruby -ne 'BEGIN { p :begin }; p :middle; END { p :end }'
:begin
:middle
:begin
:middle
:end
:end

It appears as if the END-block gets registered once per input line in both JRuby versions, and the BEGIN-block never in 9.0.4.0 and once per input line in 1.7.23. And if that isn't enough, if I pass --debug to 9.0.4.0, it runs the BEFORE-block once but the END-block twice.

This is not a feature I rely on in any way, and I just happened to stumble upon it and thought I'd report it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions