Some classes in Nokogiri
are namespaced as a group, for example Document, DocumentFragment, and Builder.
It’s sometimes necessary to look up the related class, e.g.:
XML::Builder → XML::Document HTML4::Builder → HTML4::Document HTML5::Document → HTML5::DocumentFragment
This module is included into those key classes who need to do this.
related_class
restricts matching namespaces to those matching this set.
Find a class constant within the
Some examples:
Nokogiri::XML::Document.new.related_class("DocumentFragment") # => Nokogiri::XML::DocumentFragment Nokogiri::HTML4::Document.new.related_class("DocumentFragment") # => Nokogiri::HTML4::DocumentFragment
Note this will also work for subclasses that follow the same convention, e.g.:
Loofah::HTML::Document.new.related_class("DocumentFragment") # => Loofah::HTML::DocumentFragment
And even if it’s a subclass, this will iterate through the superclasses:
class ThisIsATopLevelClass < Nokogiri::HTML4::Builder ; end ThisIsATopLevelClass.new.related_class("Document") # => Nokogiri::HTML4::Document
© 2008–2018 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo,
Patrick Mahoney, Yoko Harada, Akinori MUSHA, John Shahid, Lars Kanis
Licensed under the MIT License.
https://nokogiri.org/rdoc/Nokogiri/ClassResolver.html