Skip to content

Commit 0d00350

Browse files
committed
feat: Implement Document#parent, which always returns nil
Closes #3466
1 parent ba225a8 commit 0d00350

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA
1313
### Changed
1414

1515
* The constant `Struct::HTMLElementDescription` is no longer defined. (#3432, #3433) @viralpraxis
16+
* `Document` objects now respond to `#parent`, which will always return `nil`. Previously, the method was `undef`ed from its parent class `Node`. #3466
1617

1718

1819
### Fixed

lib/nokogiri/xml/document.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ def document
322322
self
323323
end
324324

325+
# call-seq: parent => nil
326+
#
327+
# For a Document, parent always returns +nil+
328+
def parent
329+
nil
330+
end
331+
325332
# :call-seq:
326333
# collect_namespaces() → Hash<String(Namespace#prefix) ⇒ String(Namespace#href)>
327334
#
@@ -430,7 +437,7 @@ def fragment(tags = nil)
430437
DocumentFragment.new(self, tags, root)
431438
end
432439

433-
undef_method :swap, :parent, :namespace, :default_namespace=
440+
undef_method :swap, :namespace, :default_namespace=
434441
undef_method :add_namespace_definition, :attributes
435442
undef_method :namespace_definitions, :line, :add_namespace
436443

test/xml/test_document.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,8 @@ def test_url_kwarg
711711

712712
def test_document_parent
713713
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
714-
assert_raises(NoMethodError) do
715-
xml.parent
716-
end
714+
715+
assert_nil(xml.parent)
717716
end
718717

719718
def test_document_name

0 commit comments

Comments
 (0)