# Drying my code

**URL:** <https://www.ruby-forum.com/t/drying-my-code/205935>\
**Category:** Rails\
**Created:** [April 18, 2011, 11:53pm UTC](https://www.ruby-forum.com/t/drying-my-code/205935 "2011-04-18T23:53:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 18, 2011, 11:53pm UTC](https://www.ruby-forum.com/t/drying-my-code/205935/1 "2011-04-18T23:53:02Z")

</div>

I am parsing an xml result using Hpricot, amazing …  
I have a serie of tags to be transformed as parameters, so I am  
building Hash by looping on these tags , the resulting data is oK? but  
I ma not sure that I wrote a dry code

…  
if doc.search(‘response \> error’).innerHTML.empty?  
accountTypes = []  
(doc/:accounttype).each do |accountType|  
data = {}  
…  
data[:locale] =  
(accountType/:localized/:locale/:code).innerHTML  
data[:title] =  
(accountType/:localized/:locale/:title).innerHTML  
…  
… # here is the loop over the elements  
tags = {}  
(accountType/:tag).each do |tag|  
key = (tag/:name).innerHTML.to\_s  
value = (tag/:value).innerHTML.to\_s  
tags.store(key, value)  
end  
…# end of the loop , storing the data  
data[:tags] = tags  
accountTypes \<\< data  
end

Is this loop OK ?  
tags = {}  
(accountType/:tag).each do |tag|  
key = (tag/:name).innerHTML.to\_s  
value = (tag/:value).innerHTML.to\_s  
tags.store(key, value)  
end

thanks for you fedback
