Skip to content
Permalink
Browse files

Merge pull request #598 from kostya/sort

sort tags
  • Loading branch information
alex committed Apr 10, 2013
2 parents 946205f + bb45905 commit 15bb0ec9f1552a601781a19b6785207990d470b1
@@ -182,6 +182,10 @@ def sort(&block)
dup.sort!(&block)
end

def sort_by(&block)
dup.sort_by!(&block)
end

def ==(other)
if self.equal?(other)
return true
@@ -313,4 +313,12 @@ def each_slice(num, &block)
yield buf unless buf.empty?
nil
end

def sort(&block)
to_a.sort!(&block)
end

def sort_by(&block)
to_a.sort_by!(&block)
end
end

This file was deleted.

@@ -1,10 +1,3 @@
fails:Array#sort properly handles recursive arrays
fails:compares values returned by block with 0
fails:Array#sort! sorts array in place using block value if a block given
fails:Array#sort! properly handles recursive arrays
fails:Array#sort! does not call #<=> on contained objects when invoked with a block
fails:Array#sort! does not call #<=> on elements when invoked with a block even if Array is large (Rubinius #412)
fails:Array#sort! raises a RuntimeError on a frozen array
fails:Array#sort sorts an array that has a value shifted off without a block
fails:Array#sort sorts an array that has a value shifted off with a block
fails:Array#sort compares values returned by block with 0
fails:Array#sort! properly handles recursive arrays
@@ -1,4 +1 @@
fails:Enumerable#sort_by returns an array of elements ordered by the result of block
fails:Enumerable#sort_by sorts the object by the given attribute
fails:Enumerable#sort_by returns an Enumerator when a block is not supplied
fails:Enumerable#sort_by gathers whole arrays as elements when each yields multiple
@@ -1,6 +1,2 @@
fails:Enumerable#sort sorts by the natural order as defined by <=>
fails:Enumerable#sort yields elements to the provided block
fails:Enumerable#sort sorts enumerables that contain nils
fails:Enumerable#sort compare values returned by block with 0
fails:Enumerable#sort raises an error if objects can't be compared
fails:Enumerable#sort gathers whole arrays as elements when each yields multiple
@@ -14,8 +14,16 @@ def __init__(self, space, list, listlength=None, sortblock=None):
self.space = space
self.sortblock = sortblock

def lt(self, a, b):
cmp_res = self.space.compare(a, b, self.sortblock)
def lt(self, w_a, w_b):
cmp_res = self.space.compare(w_a, w_b, self.sortblock)
return self.space.int_w(cmp_res) < 0

class RubySorterYielder(RubySorter):
def lt(self, w_a, w_b):
cmp_res = self.space.compare(
self.space.invoke_block(self.sortblock, [w_a]),
self.space.invoke_block(self.sortblock, [w_b])
)
return self.space.int_w(cmp_res) < 0

class W_ArrayObject(W_Object):
@@ -263,10 +271,19 @@ def method_clear(self, space):
return self

@classdef.method("sort!")
def method_sort(self, space, block):
@check_frozen()
def method_sort_i(self, space, block):
RubySorter(space, self.items_w, sortblock=block).sort()
return self

@classdef.method("sort_by!")
@check_frozen()
def method_sort_by_i(self, space, block):
if block is None:
return space.send(self, space.newsymbol("enum_for"), [space.newsymbol("sort_by!")])
RubySorterYielder(space, self.items_w, sortblock=block).sort()
return self

@classdef.method("reverse!")
@check_frozen()
def method_reverse_i(self, space):

0 comments on commit 15bb0ec

Please sign in to comment.