Ruby 2.7.0 リファレンスマニュアル > ライブラリ一覧 > rexml/documentライブラリ > REXML::Attributesクラス > delete

instance method REXML::Attributes#delete

delete(attribute) -> REXML::Element[permalink][rdoc]

指定した属性を取り除きます。

attribute で取り除く属性を指定します。文字列もしくは REXML::Attribute オブジェクトを指定します

self が属する要素(REXML::Element)を返します。

[PARAM] attribute:
取り除く属性(文字列もしくは REXML::Attribute オブジェクト)

require 'rexml/document'

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
      xmlns:bar="http://example.org/bar">
  <a foo:att='1' bar:att='2' att='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

a.attributes.delete("att")     # => <a foo:att='1' bar:att='2'/>
a.attributes.delete("foo:att") # => <a bar:att='2'/>
attr = a.attributes.get_attribute("bar:att")
a.attributes.delete(attr)      # => <a/>