You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
enebo
changed the title
BEGIN and END not working as in MRI
END not working as in MRI
May 23, 2017
An update with minor analysis. JRuby 1.7 is EOL and on 9k we now work as expected for BEGIN. END is not specific to -n at all. Each time we execute code which contains and END we just push it onto the end stack. So:
10.times{ END {p:end}}
It should print out once but we print out 10 times. We do correctly run the following at_exit 10 times.
BEGIN
andEND
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):
JRuby 9.0.4.0:
JRuby 1.7.23:
It appears as if the
END
-block gets registered once per input line in both JRuby versions, and theBEGIN
-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 theBEFORE
-block once but theEND
-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.
The text was updated successfully, but these errors were encountered: