diff --git a/lib/rdoc/markup/to_bs.rb b/lib/rdoc/markup/to_bs.rb index d55f64c5e7..9a1c7c6ccd 100644 --- a/lib/rdoc/markup/to_bs.rb +++ b/lib/rdoc/markup/to_bs.rb @@ -64,7 +64,6 @@ def convert_special special # Adds bold or underline mixed with backspaces def convert_string string - return string unless string.respond_to? :chars # your ruby is lame return string unless @in_b or @in_em chars = if @in_b then string.chars.map do |char| "#{char}\b#{char}" end @@ -76,4 +75,3 @@ def convert_string string end end - diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 9c207edcff..5abc374bf7 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -76,25 +76,15 @@ def self.binary?(file) s = File.read(file, 1024) or return false - have_encoding = s.respond_to? :encoding - return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") - if have_encoding then - mode = "r" - s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. - encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] - mode = "rb:#{encoding}" if encoding - s = File.open(file, mode) {|f| f.gets(nil, 1024)} - - not s.valid_encoding? - else - if 0.respond_to? :fdiv then - s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3 - else # HACK 1.8.6 - (s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3 - end - end + mode = "r" + s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. + encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] + mode = "rb:#{encoding}" if encoding + s = File.open(file, mode) {|f| f.gets(nil, 1024)} + + not s.valid_encoding? end ## @@ -308,4 +298,3 @@ def initialize top_level, file_name, content, options, stats require 'rdoc/parser/markdown' require 'rdoc/parser/rd' require 'rdoc/parser/ruby' - diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index ec50d8eba5..20ec2414e6 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -479,7 +479,7 @@ def document options @last_modified = setup_output_dir @options.op_dir, @options.force_update end - @store.encoding = @options.encoding if @options.respond_to? :encoding + @store.encoding = @options.encoding @store.dry_run = @options.dry_run @store.main = @options.main_page @store.title = @options.title diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index e2afb1fa91..f3840f327e 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -183,7 +183,7 @@ def generate @rdoc.options = options store = RDoc::Store.new - store.encoding = options.encoding if options.respond_to? :encoding + store.encoding = options.encoding store.dry_run = options.dry_run store.main = options.main_page store.title = options.title diff --git a/lib/rdoc/stats/normal.rb b/lib/rdoc/stats/normal.rb index f32db48005..ba00b6cbdf 100644 --- a/lib/rdoc/stats/normal.rb +++ b/lib/rdoc/stats/normal.rb @@ -1,8 +1,5 @@ # frozen_string_literal: false -begin - require 'io/console/size' -rescue LoadError -end +require 'io/console/size' ## # Stats printer that prints just the files being documented with a progress @@ -26,11 +23,7 @@ def print_file files_so_far, filename # Print a progress bar, but make sure it fits on a single line. Filename # will be truncated if necessary. - terminal_width = if defined?(IO) && IO.respond_to?(:console_size) - IO.console_size[1].to_i.nonzero? || 80 - else - 80 - end + terminal_width = IO.console_size[1].to_i.nonzero? || 80 max_filename_size = terminal_width - progress_bar.size if filename.size > max_filename_size then @@ -57,4 +50,3 @@ def done_adding # :nodoc: end end - diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index 37bf03fc24..aaefff8f13 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -679,12 +679,7 @@ def method_file klass_name, method_name method_name =~ /#(.*)/ method_type = $1 ? 'i' : 'c' method_name = $1 if $1 - - method_name = if ''.respond_to? :ord then - method_name.gsub(/\W/) { "%%%02x" % $&[0].ord } - else - method_name.gsub(/\W/) { "%%%02x" % $&[0] } - end + method_name = method_name.gsub(/\W/) { "%%%02x" % $&[0].ord } File.join class_path(klass_name), "#{method_name}-#{method_type}.ri" end diff --git a/test/test_rdoc_parser.rb b/test/test_rdoc_parser.rb index 732beb6629..b71d89b064 100644 --- a/test/test_rdoc_parser.rb +++ b/test/test_rdoc_parser.rb @@ -119,7 +119,7 @@ def test_class_for_forbidden end io end - tf.close! if tf.respond_to? :close! + tf.close! end def test_class_for_modeline diff --git a/test/test_rdoc_rd_block_parser.rb b/test/test_rdoc_rd_block_parser.rb index 7afa9a03dd..18ec30db0f 100644 --- a/test/test_rdoc_rd_block_parser.rb +++ b/test/test_rdoc_rd_block_parser.rb @@ -165,7 +165,7 @@ def test_parse_include_subtree assert_equal expected, parse(str) io end - tf.close! if tf.respond_to? :close! + tf.close! end def test_parse_heading diff --git a/test/test_rdoc_rdoc.rb b/test/test_rdoc_rdoc.rb index 55096d394e..0a5ff1c841 100644 --- a/test/test_rdoc_rdoc.rb +++ b/test/test_rdoc_rdoc.rb @@ -261,7 +261,7 @@ def test_parse_file_encoding assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding io end - tf.close! if tf.respond_to? :close! + tf.close! end def test_parse_file_forbidden @@ -290,7 +290,7 @@ def test_parse_file_forbidden end io end - tf.close! if tf.respond_to? :close! + tf.close! end def test_remove_unparseable @@ -398,7 +398,7 @@ def test_setup_output_dir_exists_file e.message) tempfile end - tf.close! if tf.respond_to? :close! + tf.close! end def test_setup_output_dir_exists_not_rdoc