Method: Nokogiri::XML::NodeSet#attr

Defined in:
lib/nokogiri/xml/node_set.rb

#attr(key, value = nil, &blk) ⇒ Object Also known as: set, attribute

Set the attribute key to value or the return value of blk on all Node objects in the NodeSet.



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/nokogiri/xml/node_set.rb', line 176

def attr key, value = nil, &blk
  unless Hash === key || key && (value || blk)
    return first.attribute(key)
  end

  hash = key.is_a?(Hash) ? key : { key => value }

  hash.each { |k,v| each { |el| el[k] = v || blk[el] } }

  self
end