From: William James Date: 2006-03-04T07:58:38+09:00 Subject: Re: Array comparison returning nil Julian Gall wrote: > Stephen Waits wrote: > > Maybe you could post an irb session of your own so we could see > > what's happening? > > Not really possible. I am writing a Rails application with a sortable > list on a web page. An XML_Http_request serialises the ids of the list > items and POSTs them to my action controller. By the time I see this > data it is an array of identifiers (numbers) in params[:itemlist]. > > I extract this to a local array with: > > new_item_ids = [] > params[:itemlist].each {|item| new_item_ids << item} > new_item_ids = params[:itemlist] > I want to compare this with another local array of my original > (unsorted) identifiers. i.e. > > original_item_ids.sort <=> new_item_ids.sort > > This doesn't work, although this does: > > original_item_ids.sort.join('-') == new_item_ids.sort.join('-') > > It is odd that join works to produce the expected string where <=> > thinks it has a problem. See if this raises an error: (original_item_ids + new_item_ids).sort