I have some xml that looks like this:
<accounts> <account> <name>Smith</name> </account> <account> <name>Jones</name> </account> </accounts>
In this case,
acct_hash = Hash.from_xml
produces
acct_hash['accounts']['account']
which is an Array. But if there is only one account in the xml, as in
<accounts> <account> <name>Smith</name> </account> </accounts>
then acct_hash['accounts']['account'] is a Hash.
So to turn those into Account objects I have to do slightly different things depending on the number of accounts. To figure out what to do I'm using
if acct_hash['accounts']['account'].class.to_s == "Array" ...
which works, but seems 'wrong.' Is there a better way? I wonder why Hash.from_xml doesn't just always create an Array. I'm sure there's a good reason, but it would be simpler in this case.
Thanks, -George