Here's how I would have written this method:

```ruby
def xml_to_hash(xml)
  if xml.children.length == 1 && xml.children[0].name == 'text'
    value = xml.text
  else
    value = xml.children.reduce({}) { |result, n|
      result.merge( xml_to_hash(n) ) { |key, oldval, newval|
        Array(oldval) << newval
      }
    }
  end
  
  { xml.name => value }
end
```