Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > rexml/documentライブラリ > REXML::Attributesクラス > each
each {|name, value| ... } -> ()
[permalink][rdoc]各属性の名前と値に対しブロックを呼び出します。
名前には expanded_name(REXML::Namespace#exapnded_name)が渡されます。
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
a.attributes.each do |name, value|
p [name, value]
end
# => ["foo:att", "1"]
# => ["bar:att", "2"]
# => ["att", "<"]