Ruby 2.7.0 リファレンスマニュアル > ライブラリ一覧 > rexml/documentライブラリ > REXML::Attributesクラス > length
length -> Integer
[permalink][rdoc]size -> Integer
属性の個数を返します。
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='<'/>
</root>
EOS
a = doc.get_elements("/root/a").first
p a.attributes.length # => 3