[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Xml-fun and how do I make a method shorter

Kris Thomsen

4/15/2009 6:04:00 PM

I've got a little problem.

http://pastie....

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?
--
Posted via http://www.ruby-....

2 Answers

Don Wood

4/15/2009 6:16:00 PM

0

Kris Thomsen wrote:
> I've got a little problem.
>
> http://pastie....
>
> 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
--
Posted via http://www.ruby-....

Kris Thomsen

4/15/2009 6:29:00 PM

0

Don Wood wrote:
> Kris Thomsen wrote:
>> I've got a little problem.
>>
>> http://pastie....
>>
>> 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

--
Posted via http://www.ruby-....