Skip to content

Commit e28489a

Browse files
author
|7eter l-|. l3oling
authored
Merge branch 'ruby:master' into feat/271-devcontainer
2 parents 3671e15 + 04a589a commit e28489a

24 files changed

Lines changed: 207 additions & 185 deletions

lib/rexml/attribute.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ def to_string
130130
end
131131

132132
def doctype
133-
if @element
134-
doc = @element.document
135-
doc.doctype if doc
136-
end
133+
@element&.document&.doctype
137134
end
138135

139136
# Returns the attribute value, with entities replaced
@@ -202,9 +199,7 @@ def inspect
202199
end
203200

204201
def xpath
205-
path = @element.xpath
206-
path += "/@#{self.expanded_name}"
207-
return path
202+
@element.xpath + "/@#{self.expanded_name}"
208203
end
209204

210205
def document

lib/rexml/cdata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def value
5858
# c = CData.new( " Some text " )
5959
# c.write( $stdout ) #-> <![CDATA[ Some text ]]>
6060
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
61-
Kernel.warn( "#{self.class.name}.write is deprecated", uplevel: 1)
61+
Kernel.warn( "#{self.class.name}#write is deprecated", uplevel: 1)
6262
indent( output, indent )
6363
output << START
6464
output << @string

lib/rexml/child.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def previous_sibling=(other)
8383
# Returns:: the document this child belongs to, or nil if this child
8484
# belongs to no document
8585
def document
86-
return parent.document unless parent.nil?
87-
nil
86+
parent&.document
8887
end
8988

9089
# This doesn't yet handle encodings

lib/rexml/comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def clone
4848
# ie_hack::
4949
# Needed for conformity to the child API, but not used by this class.
5050
def write( output, indent=-1, transitive=false, ie_hack=false )
51-
Kernel.warn("Comment.write is deprecated. See REXML::Formatters", uplevel: 1)
51+
Kernel.warn("#{self.class.name}#write is deprecated. See REXML::Formatters", uplevel: 1)
5252
indent( output, indent )
5353
output << START
5454
output << @string

lib/rexml/doctype.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,11 @@ def write( output, indent=0, transitive=false, ie_hack=false )
171171
end
172172

173173
def context
174-
if @parent
175-
@parent.context
176-
else
177-
nil
178-
end
174+
@parent&.context
179175
end
180176

181177
def entity( name )
182-
@entities[name].unnormalized if @entities[name]
178+
@entities[name]&.unnormalized
183179
end
184180

185181
def add child
@@ -288,8 +284,7 @@ def initialize name, middle, pub, sys
288284
end
289285

290286
def to_s
291-
context = nil
292-
context = parent.context if parent
287+
context = parent&.context
293288
notation = "<!NOTATION #{@name}"
294289
reference_writer = ReferenceWriter.new(@middle, @public, @system, context)
295290
reference_writer.write(notation)

lib/rexml/document.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def Document::entity_expansion_limit=( val )
415415
#
416416
# Deprecated. Use REXML::Security.entity_expansion_limit= instead.
417417
def Document::entity_expansion_limit
418-
return Security.entity_expansion_limit
418+
Security.entity_expansion_limit
419419
end
420420

421421
# Set the entity expansion limit. By default the limit is set to 10240.
@@ -429,7 +429,7 @@ def Document::entity_expansion_text_limit=( val )
429429
#
430430
# Deprecated. Use REXML::Security.entity_expansion_text_limit instead.
431431
def Document::entity_expansion_text_limit
432-
return Security.entity_expansion_text_limit
432+
Security.entity_expansion_text_limit
433433
end
434434

435435
attr_reader :entity_expansion_count

lib/rexml/element.rb

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ def root
473473
# Related: #root, #root_node.
474474
#
475475
def document
476-
rt = root
477-
rt.parent if rt
476+
root&.parent
478477
end
479478

480479
# :call-seq:
@@ -566,7 +565,7 @@ def prefixes
566565
prefixes = []
567566
prefixes = parent.prefixes if parent
568567
prefixes |= attributes.prefixes
569-
return prefixes
568+
prefixes
570569
end
571570

572571
# :call-seq:
@@ -625,7 +624,7 @@ def namespace(prefix=nil)
625624
ns = namespaces[prefix]
626625

627626
ns = '' if ns.nil? and prefix == 'xmlns'
628-
return ns
627+
ns
629628
end
630629

631630
# :call-seq:
@@ -957,7 +956,7 @@ def get_elements( xpath )
957956
def next_element
958957
element = next_sibling
959958
element = element.next_sibling until element.nil? or element.kind_of? Element
960-
return element
959+
element
961960
end
962961

963962
# :call-seq:
@@ -973,7 +972,7 @@ def next_element
973972
def previous_element
974973
element = previous_sibling
975974
element = element.previous_sibling until element.nil? or element.kind_of? Element
976-
return element
975+
element
977976
end
978977

979978

@@ -1023,8 +1022,7 @@ def has_text?
10231022
#
10241023
def text( path = nil )
10251024
rv = get_text(path)
1026-
return rv.value unless rv.nil?
1027-
nil
1025+
rv&.value
10281026
end
10291027

10301028
# :call-seq:
@@ -1052,7 +1050,7 @@ def get_text path = nil
10521050
else
10531051
rv = @children.find { |node| node.kind_of? Text }
10541052
end
1055-
return rv
1053+
rv
10561054
end
10571055

10581056
# :call-seq:
@@ -1096,7 +1094,7 @@ def text=( text )
10961094
old_text.replace_with( text )
10971095
end
10981096
end
1099-
return self
1097+
self
11001098
end
11011099

11021100
# :call-seq:
@@ -1147,7 +1145,7 @@ def add_text( text )
11471145
text = Text.new( text, whitespace(), nil, raw() )
11481146
end
11491147
self << text unless text.nil?
1150-
return self
1148+
self
11511149
end
11521150

11531151
# :call-seq:
@@ -1191,7 +1189,7 @@ def xpath
11911189
cur = cur.parent
11921190
path_elements << __to_xpath_helper( cur )
11931191
end
1194-
return path_elements.reverse.join( "/" )
1192+
path_elements.reverse.join( "/" )
11951193
end
11961194

11971195
#################################################
@@ -1293,7 +1291,6 @@ def attribute( name, namespace=nil )
12931291
return nil unless ( namespaces[ prefix ] == namespaces[ 'xmlns' ] )
12941292

12951293
attributes.get_attribute( name )
1296-
12971294
end
12981295

12991296
# :call-seq:
@@ -1307,7 +1304,7 @@ def attribute( name, namespace=nil )
13071304
# b.has_attributes? # => false
13081305
#
13091306
def has_attributes?
1310-
return !@attributes.empty?
1307+
!@attributes.empty?
13111308
end
13121309

13131310
# :call-seq:
@@ -1496,7 +1493,7 @@ def texts
14961493
# doc.write( out ) #-> doc is written to the string 'out'
14971494
# doc.write( $stdout ) #-> doc written to the console
14981495
def write(output=$stdout, indent=-1, transitive=false, ie_hack=false)
1499-
Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters", uplevel: 1)
1496+
Kernel.warn("#{self.class.name}#write is deprecated. See REXML::Formatters", uplevel: 1)
15001497
formatter = if indent > -1
15011498
if transitive
15021499
require_relative "formatters/transitive"
@@ -1685,11 +1682,7 @@ def []( index, name=nil)
16851682
(num += 1) == index
16861683
}
16871684
else
1688-
return XPath::first( @element, index )
1689-
#{ |element|
1690-
# return element if element.kind_of? Element
1691-
#}
1692-
#return nil
1685+
XPath::first( @element, index )
16931686
end
16941687
end
16951688

@@ -1736,7 +1729,7 @@ def []=( index, element )
17361729
else
17371730
previous.replace_with element
17381731
end
1739-
return previous
1732+
previous
17401733
end
17411734

17421735
# :call-seq:
@@ -1775,7 +1768,7 @@ def index element
17751768
child == element
17761769
end
17771770
return rv if found == element
1778-
return -1
1771+
-1
17791772
end
17801773

17811774
# :call-seq:
@@ -1854,7 +1847,7 @@ def delete_all( xpath )
18541847
@element.delete element
18551848
element.remove
18561849
end
1857-
return rv
1850+
rv
18581851
end
18591852

18601853
# :call-seq:
@@ -2181,8 +2174,7 @@ def initialize element
21812174
#
21822175
def [](name)
21832176
attr = get_attribute(name)
2184-
return attr.value unless attr.nil?
2185-
return nil
2177+
attr&.value
21862178
end
21872179

21882180
# :call-seq:
@@ -2325,19 +2317,19 @@ def get_attribute( name )
23252317
return attr
23262318
end
23272319
end
2328-
element_document = @element.document
2329-
if element_document and element_document.doctype
2320+
doctype = @element.document&.doctype
2321+
if doctype
23302322
expn = @element.expanded_name
2331-
expn = element_document.doctype.name if expn.size == 0
2332-
attr_val = element_document.doctype.attribute_of(expn, name)
2323+
expn = doctype.name if expn.size == 0
2324+
attr_val = doctype.attribute_of(expn, name)
23332325
return Attribute.new( name, attr_val ) if attr_val
23342326
end
23352327
return nil
23362328
end
23372329
if attr.kind_of? Hash
23382330
attr = attr[ @element.prefix ]
23392331
end
2340-
return attr
2332+
attr
23412333
end
23422334

23432335
# :call-seq:
@@ -2371,8 +2363,9 @@ def []=( name, value )
23712363
end
23722364

23732365
unless value.kind_of? Attribute
2374-
if @element.document and @element.document.doctype
2375-
value = Text::normalize( value, @element.document.doctype )
2366+
doctype = @element.document&.doctype
2367+
if doctype
2368+
value = Text::normalize( value, doctype )
23762369
else
23772370
value = Text::normalize( value, nil )
23782371
end
@@ -2390,7 +2383,7 @@ def []=( name, value )
23902383
else
23912384
store value.name, value
23922385
end
2393-
return @element
2386+
@element
23942387
end
23952388

23962389
# :call-seq:
@@ -2409,10 +2402,11 @@ def prefixes
24092402
each_attribute do |attribute|
24102403
ns << attribute.name if attribute.prefix == 'xmlns'
24112404
end
2412-
if @element.document and @element.document.doctype
2405+
doctype = @element.document&.doctype
2406+
if doctype
24132407
expn = @element.expanded_name
2414-
expn = @element.document.doctype.name if expn.size == 0
2415-
@element.document.doctype.attributes_of(expn).each {
2408+
expn = doctype.name if expn.size == 0
2409+
doctype.attributes_of(expn).each {
24162410
|attribute|
24172411
ns << attribute.name if attribute.prefix == 'xmlns'
24182412
}
@@ -2434,10 +2428,11 @@ def namespaces
24342428
each_attribute do |attribute|
24352429
namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
24362430
end
2437-
if @element.document and @element.document.doctype
2431+
doctype = @element.document&.doctype
2432+
if doctype
24382433
expn = @element.expanded_name
2439-
expn = @element.document.doctype.name if expn.size == 0
2440-
@element.document.doctype.attributes_of(expn).each {
2434+
expn = doctype.name if expn.size == 0
2435+
doctype.attributes_of(expn).each {
24412436
|attribute|
24422437
namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
24432438
}
@@ -2492,9 +2487,7 @@ def delete( attribute )
24922487
old.each_value{|v| repl = v}
24932488
store name, repl
24942489
end
2495-
elsif old.nil?
2496-
return @element
2497-
else # the supplied attribute is a top-level one
2490+
elsif old # the supplied attribute is a top-level one
24982491
super(name)
24992492
end
25002493
@element
@@ -2548,7 +2541,7 @@ def delete_all( name )
25482541
rv << attribute if attribute.expanded_name == name
25492542
}
25502543
rv.each{ |attr| attr.remove }
2551-
return rv
2544+
rv
25522545
end
25532546

25542547
# :call-seq:

lib/rexml/encoding.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ def encoding=(encoding)
1313
raise ArgumentError, "Bad encoding name #{original_encoding}"
1414
end
1515
end
16+
encoding = encoding.upcase if encoding
1617
return false if defined?(@encoding) and encoding == @encoding
17-
if encoding
18-
@encoding = encoding.upcase
19-
else
20-
@encoding = 'UTF-8'
21-
end
18+
@encoding = encoding || "UTF-8"
2219
true
2320
end
2421

lib/rexml/functions.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def Functions::context=(value); @@context = value; end
3939

4040
def Functions::text( )
4141
if @@context[:node].node_type == :element
42-
return @@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
42+
@@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
4343
elsif @@context[:node].node_type == :text
44-
return @@context[:node].value
44+
@@context[:node].value
4545
else
46-
return false
46+
false
4747
end
4848
end
4949

lib/rexml/instruction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def clone
4949
# See the rexml/formatters package
5050
#
5151
def write writer, indent=-1, transitive=false, ie_hack=false
52-
Kernel.warn( "#{self.class.name}.write is deprecated", uplevel: 1)
52+
Kernel.warn( "#{self.class.name}#write is deprecated", uplevel: 1)
5353
indent(writer, indent)
5454
writer << START
5555
writer << @target

0 commit comments

Comments
 (0)