Skip to content

Commit 9307446

Browse files
authored
Merge pull request #423 from rdoc/remove-ruby18-code
Cleanup code targeted Ruby 1.8
2 parents 3dbf72e + ce969b7 commit 9307446

File tree

9 files changed

+17
-43
lines changed

9 files changed

+17
-43
lines changed

lib/rdoc/markup/to_bs.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def convert_special special
6464
# Adds bold or underline mixed with backspaces
6565

6666
def convert_string string
67-
return string unless string.respond_to? :chars # your ruby is lame
6867
return string unless @in_b or @in_em
6968
chars = if @in_b then
7069
string.chars.map do |char| "#{char}\b#{char}" end
@@ -76,4 +75,3 @@ def convert_string string
7675
end
7776

7877
end
79-

lib/rdoc/parser.rb

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,15 @@ def self.binary?(file)
7676

7777
s = File.read(file, 1024) or return false
7878

79-
have_encoding = s.respond_to? :encoding
80-
8179
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
8280

83-
if have_encoding then
84-
mode = "r"
85-
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
86-
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
87-
mode = "rb:#{encoding}" if encoding
88-
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
89-
90-
not s.valid_encoding?
91-
else
92-
if 0.respond_to? :fdiv then
93-
s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
94-
else # HACK 1.8.6
95-
(s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
96-
end
97-
end
81+
mode = "r"
82+
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
83+
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
84+
mode = "rb:#{encoding}" if encoding
85+
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
86+
87+
not s.valid_encoding?
9888
end
9989

10090
##
@@ -308,4 +298,3 @@ def initialize top_level, file_name, content, options, stats
308298
require 'rdoc/parser/markdown'
309299
require 'rdoc/parser/rd'
310300
require 'rdoc/parser/ruby'
311-

lib/rdoc/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def document options
479479
@last_modified = setup_output_dir @options.op_dir, @options.force_update
480480
end
481481

482-
@store.encoding = @options.encoding if @options.respond_to? :encoding
482+
@store.encoding = @options.encoding
483483
@store.dry_run = @options.dry_run
484484
@store.main = @options.main_page
485485
@store.title = @options.title

lib/rdoc/rubygems_hook.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def generate
183183
@rdoc.options = options
184184

185185
store = RDoc::Store.new
186-
store.encoding = options.encoding if options.respond_to? :encoding
186+
store.encoding = options.encoding
187187
store.dry_run = options.dry_run
188188
store.main = options.main_page
189189
store.title = options.title

lib/rdoc/stats/normal.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# frozen_string_literal: false
2-
begin
3-
require 'io/console/size'
4-
rescue LoadError
5-
end
2+
require 'io/console/size'
63

74
##
85
# Stats printer that prints just the files being documented with a progress
@@ -26,11 +23,7 @@ def print_file files_so_far, filename
2623

2724
# Print a progress bar, but make sure it fits on a single line. Filename
2825
# will be truncated if necessary.
29-
terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
30-
IO.console_size[1].to_i.nonzero? || 80
31-
else
32-
80
33-
end
26+
terminal_width = IO.console_size[1].to_i.nonzero? || 80
3427
max_filename_size = terminal_width - progress_bar.size
3528

3629
if filename.size > max_filename_size then
@@ -57,4 +50,3 @@ def done_adding # :nodoc:
5750
end
5851

5952
end
60-

lib/rdoc/store.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,7 @@ def method_file klass_name, method_name
679679
method_name =~ /#(.*)/
680680
method_type = $1 ? 'i' : 'c'
681681
method_name = $1 if $1
682-
683-
method_name = if ''.respond_to? :ord then
684-
method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
685-
else
686-
method_name.gsub(/\W/) { "%%%02x" % $&[0] }
687-
end
682+
method_name = method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
688683

689684
File.join class_path(klass_name), "#{method_name}-#{method_type}.ri"
690685
end

test/test_rdoc_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_class_for_forbidden
119119
end
120120
io
121121
end
122-
tf.close! if tf.respond_to? :close!
122+
tf.close!
123123
end
124124

125125
def test_class_for_modeline

test/test_rdoc_rd_block_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_parse_include_subtree
165165
assert_equal expected, parse(str)
166166
io
167167
end
168-
tf.close! if tf.respond_to? :close!
168+
tf.close!
169169
end
170170

171171
def test_parse_heading

test/test_rdoc_rdoc.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_parse_file_encoding
261261
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
262262
io
263263
end
264-
tf.close! if tf.respond_to? :close!
264+
tf.close!
265265
end
266266

267267
def test_parse_file_forbidden
@@ -290,7 +290,7 @@ def test_parse_file_forbidden
290290
end
291291
io
292292
end
293-
tf.close! if tf.respond_to? :close!
293+
tf.close!
294294
end
295295

296296
def test_remove_unparseable
@@ -398,7 +398,7 @@ def test_setup_output_dir_exists_file
398398
e.message)
399399
tempfile
400400
end
401-
tf.close! if tf.respond_to? :close!
401+
tf.close!
402402
end
403403

404404
def test_setup_output_dir_exists_not_rdoc

0 commit comments

Comments
 (0)