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

instance method 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='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

p a.attributes.length # => 3