Re: Using "sort!" in a C extension (1.9 problem)
- From: Andre Nathan <andre@xxxxxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 19:30:31 -0500
On Sun, 2007-12-30 at 08:06 +0900, Andre Nathan wrote:
On Sun, 2007-12-30 at 07:34 +0900, Siep Korteling wrote:
Like this?
a=[[2],[1,2,3],[1],[1,2]]
p a.sort_by{|ar|ar.length}
Yes but in a C extension. The code I have is not working with 1.9.
Well not exactly. sort_by works but I'd prefer to use sort! with a
block, as it does the sorting in-place.
In 1.9, if I inspect "ary" below, I only see the current array element.
In 1.8, it is an array of the two elements which are being compared.
static VALUE
sort_i(VALUE ary)
{
long v1 = FIX2LONG(RARRAY_PTR(ary)[0]);
long v2 = FIX2LONG(RARRAY_PTR(ary)[1]);
return LONG2FIX(v1 - v2);
}
Andre
.
- Follow-Ups:
- Re: Using "sort!" in a C extension (1.9 problem)
- From: Ken Bloom
- Re: Using "sort!" in a C extension (1.9 problem)
- References:
- Using "sort!" in a C extension (1.9 problem)
- From: Andre Nathan
- Re: Using "sort!" in a C extension (1.9 problem)
- From: Andre Nathan
- Re: Using "sort!" in a C extension (1.9 problem)
- From: Siep Korteling
- Re: Using "sort!" in a C extension (1.9 problem)
- From: Andre Nathan
- Using "sort!" in a C extension (1.9 problem)
- Prev by Date: Re: Can Ruby be a keylogger on Win/Mac?
- Next by Date: Re: Can Ruby be a keylogger on Win/Mac?
- Previous by thread: Re: Using "sort!" in a C extension (1.9 problem)
- Next by thread: Re: Using "sort!" in a C extension (1.9 problem)
- Index(es):
Relevant Pages
|