@@ -473,8 +473,7 @@ def root
473
473
# Related: #root, #root_node.
474
474
#
475
475
def document
476
- rt = root
477
- rt . parent if rt
476
+ root &.parent
478
477
end
479
478
480
479
# :call-seq:
@@ -2325,11 +2324,11 @@ def get_attribute( name )
2325
2324
return attr
2326
2325
end
2327
2326
end
2328
- element_document = @element . document
2329
- if element_document and element_document . doctype
2327
+ doctype = @element . document &. doctype
2328
+ if doctype
2330
2329
expn = @element . expanded_name
2331
- expn = element_document . doctype . name if expn . size == 0
2332
- attr_val = element_document . doctype . attribute_of ( expn , name )
2330
+ expn = doctype . name if expn . size == 0
2331
+ attr_val = doctype . attribute_of ( expn , name )
2333
2332
return Attribute . new ( name , attr_val ) if attr_val
2334
2333
end
2335
2334
return nil
@@ -2371,8 +2370,8 @@ def []=( name, value )
2371
2370
end
2372
2371
2373
2372
unless value . kind_of? Attribute
2374
- if @element . document and @element . document . doctype
2375
- value = Text ::normalize ( value , @element . document . doctype )
2373
+ if @element . document and ( doctype = @element . document & .doctype )
2374
+ value = Text ::normalize ( value , doctype )
2376
2375
else
2377
2376
value = Text ::normalize ( value , nil )
2378
2377
end
@@ -2390,7 +2389,7 @@ def []=( name, value )
2390
2389
else
2391
2390
store value . name , value
2392
2391
end
2393
- return @element
2392
+ @element
2394
2393
end
2395
2394
2396
2395
# :call-seq:
@@ -2409,10 +2408,10 @@ def prefixes
2409
2408
each_attribute do |attribute |
2410
2409
ns << attribute . name if attribute . prefix == 'xmlns'
2411
2410
end
2412
- if @element . document and @element . document . doctype
2411
+ if @element . document and ( doctype = @element . document & .doctype )
2413
2412
expn = @element . expanded_name
2414
- expn = @element . document . doctype . name if expn . size == 0
2415
- @element . document . doctype . attributes_of ( expn ) . each {
2413
+ expn = doctype . name if expn . size == 0
2414
+ doctype . attributes_of ( expn ) . each {
2416
2415
|attribute |
2417
2416
ns << attribute . name if attribute . prefix == 'xmlns'
2418
2417
}
@@ -2434,10 +2433,10 @@ def namespaces
2434
2433
each_attribute do |attribute |
2435
2434
namespaces [ attribute . name ] = attribute . value if attribute . prefix == 'xmlns' or attribute . name == 'xmlns'
2436
2435
end
2437
- if @element . document and @element . document . doctype
2436
+ if @element . document and ( doctype = @element . document & .doctype )
2438
2437
expn = @element . expanded_name
2439
- expn = @element . document . doctype . name if expn . size == 0
2440
- @element . document . doctype . attributes_of ( expn ) . each {
2438
+ expn = doctype . name if expn . size == 0
2439
+ doctype . attributes_of ( expn ) . each {
2441
2440
|attribute |
2442
2441
namespaces [ attribute . name ] = attribute . value if attribute . prefix == 'xmlns' or attribute . name == 'xmlns'
2443
2442
}
0 commit comments