Xml-fun and how do I make a method shorter

K

Kris Thomsen

I've got a little problem.

http://pastie.org/447561

I want the parseFile-method to do what the outcommented-method do - just
shorter and prettier.
Anyone who can give some tips on how I can do this?
 
D

Don Wood

Kris said:
I've got a little problem.

http://pastie.org/447561

I want the parseFile-method to do what the outcommented-method do - just
shorter and prettier.
Anyone who can give some tips on how I can do this?

You have no clear return value, so I don't know exactly how you want
those arrays returned. I went ahead and put them in a Hash and returned
that.

def parseFile file
data= { 'code' => [], 'desc' => [], 'rate' => [] }
file.search('currency').each do |currency|
data.each_pair { |k,a| a.push currency.attributes[k] }
end
return data
end
 
K

Kris Thomsen

Don said:
Kris said:
I've got a little problem.

http://pastie.org/447561

I want the parseFile-method to do what the outcommented-method do - just
shorter and prettier.
Anyone who can give some tips on how I can do this?

You have no clear return value, so I don't know exactly how you want
those arrays returned. I went ahead and put them in a Hash and returned
that.

def parseFile file
data= { 'code' => [], 'desc' => [], 'rate' => [] }
file.search('currency').each do |currency|
data.each_pair { |k,a| a.push currency.attributes[k] }
end
return data
end

Oh, pretty.
But. How do I get the informations from my hashes? The idea was that I
line the values up beside eachother. Like:

Code Desc. Rate
EUR Euro 7.45
USD American Dollars 5.55
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top