[ruby-core:102177] [Ruby master Bug#17564] Source command in irb exits after reading and evaluating the file
From:
rsharman@...
Date:
2021-01-19 23:43:49 UTC
List:
ruby-core #102177
Issue #17564 has been reported by rsharman (Richard Sharman). ---------------------------------------- Bug #17564: Source command in irb exits after reading and evaluating the file https://bugs.ruby-lang.org/issues/17564 * Author: rsharman (Richard Sharman) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin17] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- In the irb of ruby 2.3.7 (the version that comes with Macos) the βsourceβ command allows ruby code to be fed to irb as if it were typed in by hand. This has a advantage over the βloadβ command because variables can be setup not just functions. However, for ruby versions 2.7.2 and 3.0 irbβs βsourceβ command exits after reading and evaluating everything. This is not very useful in an interactive environment. I found what I think was a crucial difference between version 2.3.7 and later versions: in function "each_top_level_statement" of irb/ruby-lex.rb the statement ``` break unless l ``` was replaced by ``` break if @io.eof? ``` When I replaced βbreak if @io.eof?β by βbreak unless lβ in version 3.0.0 the old behaviour of the βsourceβ command returned! I can now read in ruby code, including variables, and use them. See file patch for a unified diff of the change. I donβt understand why this βfixβ works, and realize it may not be valid, but I am submitting it in case it is legitimate and can be used. A trivial file demonstrates the problem: file βa.rbβ simply sets variable βaβ. To test, invoke irb and issue the command βsource βa.rbββ. The expected behaviour is you are left at the irb prompt and variable a is valid. The behaviour in verions 3.0.0 without the fix is irb exits. See file a.rb and output with and without fix in file Log. ---Files-------------------------------- a.rb (9 Bytes) Log (298 Bytes) Patch (383 Bytes) -- 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>