Skip to content

Commit

Permalink
add the implementation of NSArray#sort_by!
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 2, 2012
1 parent a6148e0 commit 25b095b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions NSArray.m
Expand Up @@ -616,6 +616,25 @@
return nsary_sort_bang(result, 0);
}

static VALUE
nsary_sort_by_i(VALUE i)
{
return rb_yield(OC2RB(i));
}

static VALUE
nsary_sort_by_bang(id rcv, SEL sel)
{
RETURN_ENUMERATOR(rcv, 0, 0);

CHECK_MUTABLE(rcv);
VALUE sorted = rb_objc_block_call((VALUE)rcv, sel_registerName("sort_by"), 0, 0,
nsary_sort_by_i, 0);
TRY_MOP([rcv setArray:(id)sorted]);

return (VALUE)rcv;
}

static VALUE
collect(id rcv)
{
Expand Down Expand Up @@ -1029,6 +1048,7 @@
rb_objc_define_method(rb_cArray, "reverse!", nsary_reverse_bang, 0);
rb_objc_define_method(rb_cArray, "sort", nsary_sort, 0);
rb_objc_define_method(rb_cArray, "sort!", nsary_sort_bang, 0);
rb_objc_define_method(rb_cArray, "sort_by!", nsary_sort_by_bang, 0);
rb_objc_define_method(rb_cArray, "collect", nsary_collect, 0);
rb_objc_define_method(rb_cArray, "collect!", nsary_collect_bang, 0);
rb_objc_define_method(rb_cArray, "map", nsary_collect, 0);
Expand Down

0 comments on commit 25b095b

Please sign in to comment.