Project

General

Profile

Bug #16647

Redefining $/ causes irb to misbehave

Added by mehagar (Michael Hagar) about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
[ruby-core:97234]

Description

If I start irb and then do:

$/ = "asdf"

then every character I type shows a newline on the irb console. Previous versions of ruby do not have this behavior, and it is annoying.

Updated by Eregon (Benoit Daloze) about 1 month ago

Out of curiosity, why do you overwrite $/?

My personal opinion is we should deprecate all these variables affecting default separators,
they tend to break any non-trivial program, not just IRB, and explicit seems always clearer.

Updated by Hanmac (Hans Mackowiak) about 1 month ago

Related to https://bugs.ruby-lang.org/issues/14240

changing these variables is deprecated now, and it shows a warning

Updated by aycabta (aycabta .) about 1 month ago

  • Status changed from Open to Closed

It was a problem with Reline. I fixed it by https://github.com/ruby/reline/pull/129.

My personal opinion is we should deprecate all these variables affecting default separators,
they tend to break any non-trivial program, not just IRB, and explicit seems always clearer.

I think so, but...maybe, so many beginners use IRB to check Ruby's features.
It's just my opinion, and it was easy to fix. So I fixed it for beginners.

hanging these variables is deprecated now, and it shows a warning

Yes, nobu (Nobuyoshi Nakada) said "I forgot it (#14240) to create Pull Request (https://github.com/ruby/ruby/pull/2920) even I created a branch." after I talked about this issue (#16647) to @nobu.
I'll remove the fix of Reline after the global variables are completely removed.

#4

Updated by mehagar (Michael Hagar) about 1 month ago

Eregon (Benoit Daloze) wrote in #note-1:

Out of curiosity, why do you overwrite $/?

My personal opinion is we should deprecate all these variables affecting default separators,
they tend to break any non-trivial program, not just IRB, and explicit seems always clearer.

I was following along an example from the book "The Well Grounded Rubyist, 3rd edition", that was illustrating how IO objects iterate.

Also available in: Atom PDF