Commit Graph

1 Commits

Author SHA1 Message Date
Jarek Prokop
50e278ea0a Fix printing warnings when using IRB from a script.
IRB, when used from within ruby code using simple `require 'irb'; binding.irb`,
a lot of warning messages about already initialized constants, similar to:
"/usr/share/ruby/irb/ruby-lex.rb:123: warning: already initialized constant RubyLex::ERROR_TOKENS"
"/usr/share/gems/gems/irb-1.3.5/lib/irb/ruby-lex.rb:123: warning: previous definition of ERROR_TOKENS was here"
are printed.

The warnings can be observed when invoking irb by calling `binding.irb` from
Ruby code.

$ echo "" | ruby -e binding.irb

Actual results:

~~~
/usr/share/ruby/irb/ruby-lex.rb:123: warning: already initialized constant RubyLex::ERROR_TOKENS
/usr/share/gems/gems/irb-1.3.5/lib/irb/ruby-lex.rb:123: warning: previous definition of ERROR_TOKENS was here
/usr/share/ruby/irb/color.rb:8: warning: already initialized constant IRB::Color::CLEAR
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:8: warning: previous definition of CLEAR was here
/usr/share/ruby/irb/color.rb:9: warning: already initialized constant IRB::Color::BOLD
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:9: warning: previous definition of BOLD was here
/usr/share/ruby/irb/color.rb:10: warning: already initialized constant IRB::Color::UNDERLINE
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:10: warning: previous definition of UNDERLINE was here
/usr/share/ruby/irb/color.rb:11: warning: already initialized constant IRB::Color::REVERSE
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:11: warning: previous definition of REVERSE was here
/usr/share/ruby/irb/color.rb:12: warning: already initialized constant IRB::Color::RED
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:12: warning: previous definition of RED was here
/usr/share/ruby/irb/color.rb:13: warning: already initialized constant IRB::Color::GREEN
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:13: warning: previous definition of GREEN was here
/usr/share/ruby/irb/color.rb:14: warning: already initialized constant IRB::Color::YELLOW
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:14: warning: previous definition of YELLOW was here
/usr/share/ruby/irb/color.rb:15: warning: already initialized constant IRB::Color::BLUE
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:15: warning: previous definition of BLUE was here
/usr/share/ruby/irb/color.rb:16: warning: already initialized constant IRB::Color::MAGENTA
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:16: warning: previous definition of MAGENTA was here
/usr/share/ruby/irb/color.rb:17: warning: already initialized constant IRB::Color::CYAN
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:17: warning: previous definition of CYAN was here
/usr/share/ruby/irb/color.rb:19: warning: already initialized constant IRB::Color::TOKEN_KEYWORDS
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:19: warning: previous definition of TOKEN_KEYWORDS was here
/usr/share/ruby/irb/color.rb:26: warning: already initialized constant IRB::Color::ALL
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:26: warning: previous definition of ALL was here
/usr/share/ruby/irb/color.rb:32: warning: already initialized constant IRB::Color::TOKEN_SEQ_EXPRS
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:32: warning: previous definition of TOKEN_SEQ_EXPRS was here
/usr/share/ruby/irb/color.rb:75: warning: already initialized constant IRB::Color::ERROR_TOKENS
/usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:75: warning: previous definition of ERROR_TOKENS was here
Switch to inspect mode.
~~~

Expected results:

No warning

Patching the requires inside rubygem-irb to use `require_relative`
instead resolves the situation.

Patch composed from:
https://github.com/ruby/irb/pull/335
848d339f2e
https://github.com/ruby/irb/pull/336
d5060f7668
https://github.com/ruby/irb/pull/338
99d3aa979d

Resolves: RHEL-83044
2025-03-27 15:03:49 +01:00