From 01f615a671191d11ce6420abdbe6f840e97bdab6 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 8 Jul 2023 22:50:42 +0100 Subject: [PATCH 1/2] Remove unused InputMethod#initialize The constructor takes a `file_name` argument, but it is never used. The only input method that needs a file is `FileInputMethod`, which has its own constructor to take a file object directly. So the constructor in `InputMethod` is not needed and its child classes don't need to call `super` in their constructors. --- lib/irb/input-method.rb | 13 ------------- test/irb/helper.rb | 1 - 2 files changed, 14 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 4e049b22d..c35eac4fa 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -10,16 +10,7 @@ require 'reline' module IRB - STDIN_FILE_NAME = "(line)" # :nodoc: class InputMethod - - # Creates a new input method object - def initialize(file = STDIN_FILE_NAME) - @file_name = file - end - # The file name of this input method, usually given during initialization. - attr_reader :file_name - # The irb prompt associated with this input method attr_accessor :prompt @@ -56,7 +47,6 @@ def inspect class StdioInputMethod < InputMethod # Creates a new input method object def initialize - super @line_no = 0 @line = [] @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") @@ -130,7 +120,6 @@ def open(file, &block) # Creates a new input method object def initialize(file) - super @io = file.is_a?(IO) ? file : File.open(file) @external_encoding = @io.external_encoding end @@ -183,7 +172,6 @@ def initialize if Readline.respond_to?(:encoding_system_needs) IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false) end - super @line_no = 0 @line = [] @@ -261,7 +249,6 @@ class RelineInputMethod < InputMethod # Creates a new input method object using Reline def initialize IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false) - super @line_no = 0 @line = [] diff --git a/test/irb/helper.rb b/test/irb/helper.rb index 55f9e083e..ae02373d4 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -17,7 +17,6 @@ class TestInputMethod < ::IRB::InputMethod attr_reader :list, :line_no def initialize(list = []) - super("test") @line_no = 0 @list = list end From 4e26b31dec5a659dea4501456da4f687448a12ab Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 8 Jul 2023 22:53:24 +0100 Subject: [PATCH 2/2] Remove unused FileInputMethod#file_name --- lib/irb/input-method.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index c35eac4fa..1e0afab24 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -123,8 +123,6 @@ def initialize(file) @io = file.is_a?(IO) ? file : File.open(file) @external_encoding = @io.external_encoding end - # The file name of this input method, usually given during initialization. - attr_reader :file_name # Whether the end of this input method has been reached, returns +true+ if # there is no more data to read.