From 81b604fb005b2dfa9601e0dabcdacfca6d8f3fba Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 16 Jan 2022 22:20:05 +0000 Subject: [PATCH] [ruby/irb] Use require_relative to require lib files 1. `require` can mislead Ruby to load system irb's files and cause constant redefined warnings as other code loads the same module/class from lib folder. 2. Most files already use `require_relative`. https://github.com/ruby/irb/commit/848d339f2e --- lib/irb/color.rb | 2 +- lib/irb/color_printer.rb | 2 +- lib/irb/inspector.rb | 2 +- libexec/irb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/irb/color.rb b/lib/irb/color.rb index 40e9e04c97..f9204f4c98 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'reline' require 'ripper' -require 'irb/ruby-lex' +require_relative 'ruby-lex' module IRB # :nodoc: module Color diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb index 30c6825750..78f0b51520 100644 --- a/lib/irb/color_printer.rb +++ b/lib/irb/color_printer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true require 'pp' -require 'irb/color' +require_relative 'color' module IRB class ColorPrinter < ::PP diff --git a/lib/irb/inspector.rb b/lib/irb/inspector.rb index c2f3b605db..8c37c0f174 100644 --- a/lib/irb/inspector.rb +++ b/lib/irb/inspector.rb @@ -114,7 +114,7 @@ module IRB # :nodoc: end result } - Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require "irb/color_printer"}){|v| + Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v| if IRB.conf[:MAIN_CONTEXT]&.use_colorize? IRB::ColorPrinter.pp(v, '').chomp else diff --git a/libexec/irb b/libexec/irb index c64ee85fbd..ffc97867d0 100755 --- a/libexec/irb +++ b/libexec/irb @@ -6,6 +6,6 @@ # by Keiju ISHITSUKA(keiju@ruby-lang.org) # -require "irb" +require_relative '../lib/irb' IRB.start(__FILE__)