Project

General

Profile

Actions

Bug #16647

closed

Redefining $/ causes irb to misbehave

Added by mehagar (Michael Hagar) about 4 years ago. Updated about 4 years ago.

Status:
Closed
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 4 years 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 4 years 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 4 years 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 (Nobuyoshi Nakada).
I'll remove the fix of Reline after the global variables are completely removed.

Actions #4

Updated by mehagar (Michael Hagar) about 4 years 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0