From 8934b5c62852975fd667c070ce8d0f2c2c5512e3 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 28 Feb 2023 15:24:53 -0500 Subject: [PATCH] feat: SaveOptions#inspect shows the names of the set options Closes #2767 --- CHANGELOG.md | 3 +++ lib/nokogiri/xml/node/save_options.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92dbae3942c..5ef0165c628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA ### Improved +* `Nokogiri::XML::Node::SaveOptions#inspect` now shows the names of the options set in the bitmask, similar to `ParseOptions`. [[#2767](https://github.com/sparklemotion/nokogiri/issues/2767)] + + ### Deprecated ### Performance diff --git a/lib/nokogiri/xml/node/save_options.rb b/lib/nokogiri/xml/node/save_options.rb index 2d4a0c4c29e..9e2652c6776 100644 --- a/lib/nokogiri/xml/node/save_options.rb +++ b/lib/nokogiri/xml/node/save_options.rb @@ -62,6 +62,14 @@ def #{constant.downcase}? end alias_method :to_i, :options + + def inspect + options = [] + self.class.constants.each do |k| + options << k.downcase if send(:"#{k.downcase}?") + end + super.sub(/>$/, " " + options.join(", ") + ">") + end end end end