On 7/7/06, Paul Hepworth <paul / hepworthinc.com> wrote:
> I am new to Ruby and have an issue with a xmlsimple object resulting
> from a 3rd party webservice.
>
> The xml has nodes that have hyphens (-) in the names...
>
> Example XML:
>
> <object>
>  <tree-lists>
>    <tree-list>
>    ...
>    </tree-list>
>    ...
>  </tree-lists>
> </object>
>
> Example Ruby :
>
> for tlist in object.tree-lists
>  ...
> end

I'm not certain how xmlsimple works, but I assume it's dynamically
generating methods (or using method_missing) to map methods as
pseudo-properties onto the XML elements. If so, this *might* work:

  for tlist in object.send(:'tree-lists')
    ...
  end

Ruby doesn't like you having methods with hyphens in the name
*syntactically*, but semantically, there's nothing wrong with it. You
can create methods with hyphenated names using define_method, just not
def. And you can call methods with hyphenated names using send, just
not the standard dot syntax. It is of course discouraged, being highly
ugly, but it is *possible*. :)

Jacob Fugal