aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/help.rb2
-rw-r--r--lib/irb/input-method.rb3
-rw-r--r--lib/irb/magic-file.rb38
3 files changed, 1 insertions, 42 deletions
diff --git a/lib/irb/help.rb b/lib/irb/help.rb
index a16626c7dd..ca12810de1 100644
--- a/lib/irb/help.rb
+++ b/lib/irb/help.rb
@@ -4,8 +4,6 @@
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
#
-require_relative 'magic-file'
-
module IRB
# Outputs the irb help message, see IRB@Command+line+options.
def IRB.print_usage
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index bc61805ebb..ed5c53c385 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -5,7 +5,6 @@
#
require_relative 'src_encoding'
-require_relative 'magic-file'
require_relative 'completion'
require 'io/console'
require 'reline'
@@ -132,7 +131,7 @@ module IRB
# Creates a new input method object
def initialize(file)
super
- @io = file.is_a?(IO) ? file : IRB::MagicFile.open(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.
diff --git a/lib/irb/magic-file.rb b/lib/irb/magic-file.rb
deleted file mode 100644
index 34e06d64b3..0000000000
--- a/lib/irb/magic-file.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: false
-module IRB
- class << (MagicFile = Object.new)
- # see parser_magic_comment in parse.y
- ENCODING_SPEC_RE = %r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
-
- def open(path)
- io = File.open(path, 'rb')
- line = io.gets
- line = io.gets if line[0,2] == "#!"
- encoding = detect_encoding(line)
- internal_encoding = encoding
- encoding ||= IRB.default_src_encoding
- io.rewind
- io.set_encoding(encoding, internal_encoding)
-
- if block_given?
- begin
- return (yield io)
- ensure
- io.close
- end
- else
- return io
- end
- end
-
- private
- def detect_encoding(line)
- return unless line[0] == ?#
- line = line[1..-1]
- line = $1 if line[/-\*-\s*(.*?)\s*-*-$/]
- return nil unless ENCODING_SPEC_RE =~ line
- encoding = $1
- return encoding.sub(/-(?:mac|dos|unix)/i, '')
- end
- end
-end