From 0b054ff5cd5d03914982845f4ac7db432c49853d Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 15 Mar 2025 12:46:39 +0000 Subject: [PATCH] Expand single-letter variable names for better readability --- lib/rdoc/parser.rb | 12 +++--- lib/rdoc/parser/prism_ruby.rb | 70 +++++++++++++++++------------------ lib/rdoc/parser/ruby.rb | 24 ++++++------ lib/rdoc/ri/driver.rb | 6 +-- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index d027711aea..2f3f3cc50f 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -74,17 +74,17 @@ def self.alias_extension(old_ext, new_ext) def self.binary?(file) return false if file =~ /\.(rdoc|txt)$/ - s = File.read(file, 1024) or return false + string = File.read(file, 1024) or return false - return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") + return true if string[0, 2] == Marshal.dump('')[0, 2] or string.index("\x00") mode = 'r:utf-8' # default source encoding has been changed to utf-8 - s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. - encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] + string.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. + encoding = string[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] mode = "rb:#{encoding}" if encoding - s = File.open(file, mode) {|f| f.gets(nil, 1024)} + string = File.open(file, mode) {|f| f.gets(nil, 1024)} - not s.valid_encoding? + !string.valid_encoding? end ## diff --git a/lib/rdoc/parser/prism_ruby.rb b/lib/rdoc/parser/prism_ruby.rb index babd02f18f..5ded977491 100644 --- a/lib/rdoc/parser/prism_ruby.rb +++ b/lib/rdoc/parser/prism_ruby.rb @@ -289,12 +289,12 @@ def handle_meta_method_comment(comment, node) if attributes attributes.each do |attr| - a = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton) - a.store = @store - a.line = line_no - record_location(a) - @container.add_attribute(a) - a.visibility = visibility + attr_obj = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton) + attr_obj.store = @store + attr_obj.line = line_no + record_location(attr_obj) + @container.add_attribute(attr_obj) + attr_obj.visibility = visibility end elsif line_no || node method_name ||= call_node_name_arguments(node).first if is_call_node @@ -401,13 +401,13 @@ def visible_tokens_from_location(location) def change_method_visibility(names, visibility, singleton: @singleton) new_methods = [] - @container.methods_matching(names, singleton) do |m| - if m.parent != @container - m = m.dup - record_location(m) - new_methods << m + @container.methods_matching(names, singleton) do |method| + if method.parent != @container + method = method.dup + record_location(method) + new_methods << method else - m.visibility = visibility + method.visibility = visibility end end new_methods.each do |method| @@ -449,13 +449,13 @@ def add_alias_method(old_name, new_name, line_no) comment = consecutive_comment(line_no) handle_consecutive_comment_directive(@container, comment) visibility = @container.find_method(old_name, @singleton)&.visibility || :public - a = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton) - handle_modifier_directive(a, line_no) - a.store = @store - a.line = line_no - record_location(a) - if should_document?(a) - @container.add_alias(a) + alias_obj = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton) + handle_modifier_directive(alias_obj, line_no) + alias_obj.store = @store + alias_obj.line = line_no + record_location(alias_obj) + if should_document?(alias_obj) + @container.add_alias(alias_obj) @container.find_method(new_name, @singleton)&.visibility = visibility end end @@ -468,13 +468,13 @@ def add_attributes(names, rw, line_no) return unless @container.document_children names.each do |symbol| - a = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton) - a.store = @store - a.line = line_no - record_location(a) - handle_modifier_directive(a, line_no) - @container.add_attribute(a) if should_document?(a) - a.visibility = visibility # should set after adding to container + attr_obj = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton) + attr_obj.store = @store + attr_obj.line = line_no + record_location(attr_obj) + handle_modifier_directive(attr_obj, line_no) + @container.add_attribute(attr_obj) if should_document?(attr_obj) + attr_obj.visibility = visibility # should set after adding to container end end @@ -483,11 +483,11 @@ def add_includes_extends(names, rdoc_class, line_no) # :nodoc: comment = consecutive_comment(line_no) handle_consecutive_comment_directive(@container, comment) names.each do |name| - ie = @container.add(rdoc_class, name, '') - ie.store = @store - ie.line = line_no - ie.comment = comment - record_location(ie) + include_extend_obj = @container.add(rdoc_class, name, '') + include_extend_obj.store = @store + include_extend_obj.line = line_no + include_extend_obj.comment = comment + record_location(include_extend_obj) end end @@ -652,10 +652,10 @@ def add_constant(constant_name, rhs_name, start_line, end_line) @container.find_module_named(rhs_name) end if mod && constant.document_self - a = @container.add_module_alias(mod, rhs_name, constant, @top_level) - a.store = @store - a.line = start_line - record_location(a) + module_alias = @container.add_module_alias(mod, rhs_name, constant, @top_level) + module_alias.store = @store + module_alias.line = start_line + record_location(module_alias) end end diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index d11497be22..729cfe2990 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -368,15 +368,15 @@ def get_class_or_module container, ignore_constants = false container = container.find_module_named name_t[:text] container ||= if ignore_constants then - c = RDoc::NormalModule.new name_t[:text] - c.store = @store - new_modules << [prev_container, c] - c + module_obj = RDoc::NormalModule.new name_t[:text] + module_obj.store = @store + new_modules << [prev_container, module_obj] + module_obj else - c = prev_container.add_module RDoc::NormalModule, name_t[:text] - c.ignore unless prev_container.document_children - @top_level.add_to_classes_or_modules c - c + module_obj = prev_container.add_module RDoc::NormalModule, name_t[:text] + module_obj.ignore unless prev_container.document_children + @top_level.add_to_classes_or_modules module_obj + module_obj end record_location container @@ -700,10 +700,10 @@ def make_message message # Creates a comment with the correct format def new_comment comment, line_no = nil - c = RDoc::Comment.new comment, @top_level, :ruby - c.line = line_no - c.format = @markup - c + comment_obj = RDoc::Comment.new comment, @top_level, :ruby + comment_obj.line = line_no + comment_obj.format = @markup + comment_obj end ## diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 9f655f50b7..5c224a7ba6 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -806,9 +806,9 @@ def complete_method name, klass, selector, completions # :nodoc: def display document page do |io| - f = formatter(io) - f.width = @width if @width and f.respond_to?(:width) - text = document.accept f + formatter = formatter(io) + formatter.width = @width if @width and formatter.respond_to?(:width) + text = document.accept formatter io.write text end