Well, you could just do

    [7,4,9,55,98,11,42].sort

;-) That's much more optimized than anything else you can do in one line...

What you described is called a "Selection sort" (
http://en.wikipedia.org/wiki/Selection_sort)
If you really must implement it yourself (why in one line?)
You could try something like this:

0.upto(n.size-1) do |i|
    lowest_idx = i + n[i..-1].index(n[i..-1].min)
    n[lowest_idx], n[i] = n[i], n[lowest_idx]
end

Which is already pretty hackishly short and inefficient. ;-)
Greetz!

2009/7/11 Haris Bogdanovi <fbogdanovi / xnet.hr>

> Hi.
>
> I would like to implement a sorting algorithm in one line of code if
> possible.
>
> n=[7,4,9,55,98,11,42]
> n.inject(n[0]) {|min, i| min=i if i<min; min}
>
> I first find lowest number in list and then would like to replace it with
> first element. After that I need to start from the second element, find the
> lowest element, replace it with that second element and so on till I reach
> the end of a list.
> I don't know how this sorting algorithm is called ?
>
> I managed to find the minimum in the above code. What next ? How to replace
> two elements ?
> The result is a number object. Where do I (in general) put a dot in above
> expression to perform some methods on that object (when expression has a
> block {} of code in itself ) ?
>
> Can you also show me that for a quick sort ?
>
> Thanks
> Haris
>
>
>
>