Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2230 from kachick/fix-array-delete

Fix Array#delete for 1.9
  • Loading branch information...
commit d39ddd684693d5cd0b716271d7254ae9aa2afdb6 2 parents f0fcc54 + b93a814
@jc00ke jc00ke authored
View
31 kernel/common/array.rb
@@ -373,37 +373,6 @@ def cycle(n=nil, &block)
nil
end
- def delete(obj)
- key = undefined
- i = @start
- total = i + @total
- tuple = @tuple
-
- while i < total
- if tuple.at(i) == obj
- # We MUST check frozen here, not at the top, because MRI
- # requires that #delete not raise unless an element would
- # be deleted.
- Rubinius.check_frozen
- tuple.put i, key
- end
- i += 1
- end
-
- deleted = @tuple.delete @start, @total, key
- if deleted > 0
- @total -= deleted
- reallocate_shrink()
- return obj
- end
-
- if block_given?
- yield
- else
- nil
- end
- end
-
def delete_at(idx)
Rubinius.check_frozen
View
31 kernel/common/array18.rb
@@ -238,6 +238,37 @@ def concat(other)
concat other
end
+ def delete(obj)
+ key = undefined
+ i = @start
+ total = i + @total
+ tuple = @tuple
+
+ while i < total
+ if tuple.at(i) == obj
+ # We MUST check frozen here, not at the top, because MRI
+ # requires that #delete not raise unless an element would
+ # be deleted.
+ Rubinius.check_frozen
+ tuple.put i, key
+ end
+ i += 1
+ end
+
+ deleted = @tuple.delete @start, @total, key
+ if deleted > 0
+ @total -= deleted
+ reallocate_shrink()
+ return obj
+ end
+
+ if block_given?
+ yield
+ else
+ nil
+ end
+ end
+
def flatten(level=-1)
level = Rubinius::Type.coerce_to(level, Integer, :to_int)
return self if level == 0
View
33 kernel/common/array19.rb
@@ -204,6 +204,39 @@ def concat(other)
concat other
end
+ def delete(obj)
+ key = undefined
+ i = @start
+ total = i + @total
+ tuple = @tuple
+
+ while i < total
+ element = tuple.at i
+ if element == obj
+ # We MUST check frozen here, not at the top, because MRI
+ # requires that #delete not raise unless an element would
+ # be deleted.
+ Rubinius.check_frozen
+ tuple.put i, key
+ last_matched_element = element
+ end
+ i += 1
+ end
+
+ deleted = @tuple.delete @start, @total, key
+ if deleted > 0
+ @total -= deleted
+ reallocate_shrink()
+ return last_matched_element
+ end
+
+ if block_given?
+ yield
+ else
+ nil
+ end
+ end
+
def flatten(level=-1)
level = Rubinius::Type.coerce_to(level, Integer, :to_int)
return self.dup if level == 0
View
1  spec/tags/19/ruby/core/array/delete_tags.txt
@@ -1 +0,0 @@
-fails:Array#delete returns the last element in the array for which object is equal under #==
Please sign in to comment.
Something went wrong with that request. Please try again.