unknown wrote:
> 
> that is widely understood to mean 'least suprise to matz'.  fyi.
> 
I was using that a little tongue in cheek.

>>
>> So this allows a sort across the entire array and it should be noted
>> that it does an index step through comparison so [1,1,2] would come
>> after [1,1,1].  However this means I am limited to sorting only via this
>> mechanism.
> 
> no, it doesn't:
> 
>    harp :~ > cat a.rb
> 
>    m = [9,8,7], [1,2,3]
> 
>    p m.sort_by{|row| row.last}
> 
>    p m.sort{|a,b| a[2] <=> b[2]}
> 
> 
>    harp :~ > ruby a.rb
>    [[1, 2, 3], [9, 8, 7]]
>    [[1, 2, 3], [9, 8, 7]]
> 

I have not looked much at how sort_by is used, but I do see how that can
be beneficial in some situations.  When I stated "such as sorting" above
that was just one example; I see that I should have given others since
the sorting piece is apparently available.  I am really looking for
flexibility somewhat similar to a database table but on small dynamic
sets of data.

> 
>> What is happening is that in a[0..1][0] a[0..1] is grabbing the subset
>> of arrays 0 to 1 and then the second index [0] is indexing back in to
>> the subset.  What looks like it should be happening is that a[0..1][0]
>> is defining the set of the arrays where we wish to retrieve the 0 index.
> 
> i understand why you might think that - but it doesn't really make 
> sense.  if
> what you said were true then this
> 
>    p a[1][1]  #=> 2
> 
> would print an array and not 2.  in otherwords if you want the last 
> index on a
> 2d array to return a column vector then access the elements would always
> require 3 indices!  eg. you'd need
> 
>    p a[1][1][1]  #=> 2
> 
I was saying that the syntax to include multiple rows a[n..m] was
handled differently than indexing a single row a[n].  How it was doing
this was just a conjecture based on the results.

> and that would be strange indeed.  in addition column wise read access
> requires column wise write access so one would be able to do
> 
>    a[0..1][0] = a_new_column
> 
> again, requiring tripple indices to assign elements.
> 
> 
> i think you are looking for something like narray, which is on rubyforge 
> and
> quite powerful.  it supports n-dimensional arrays with compound 
> indicies:
> 

I will check out narray to see if it fits my needs.  Thanks for your
response.

-joe

> 
> 
> regards.
> 
> 
> 
> -a

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