Created
July 21, 2010 08:45
-
-
Save kronos/484235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 05b4614e120a93fd73e096264f00695c1c84b75e Mon Sep 17 00:00:00 2001 | |
| From: Ivan Samsonov <hronya@gmail.com> | |
| Date: Wed, 21 Jul 2010 12:43:09 +0400 | |
| Subject: [PATCH 1/2] One more spec for Array#delete that rubinius doesn't handle | |
| --- | |
| spec/ruby/core/array/delete_spec.rb | 6 ++++++ | |
| 1 files changed, 6 insertions(+), 0 deletions(-) | |
| diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb | |
| index bb1893c..d584e83 100644 | |
| --- a/spec/ruby/core/array/delete_spec.rb | |
| +++ b/spec/ruby/core/array/delete_spec.rb | |
| @@ -30,6 +30,12 @@ describe "Array#delete" do | |
| [].delete('a') {:not_found}.should == :not_found | |
| end | |
| + it "returns nil if no block given and array is empty" do | |
| + a = [1] | |
| + a.shift | |
| + a.delete(nil).should == nil | |
| + end | |
| + | |
| ruby_version_is '' ... '1.9' do | |
| it "raises a TypeError on a frozen array if a modification would take place" do | |
| lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(TypeError) | |
| -- | |
| 1.6.6.1 | |
| From 58ca3ae8f9c7f382a6fd69ebcf35dc2e06791a09 Mon Sep 17 00:00:00 2001 | |
| From: Ivan Samsonov <hronya@gmail.com> | |
| Date: Wed, 21 Jul 2010 12:43:45 +0400 | |
| Subject: [PATCH 2/2] Ensure array is not empty in delete method | |
| --- | |
| kernel/common/array.rb | 14 +++++++++----- | |
| 1 files changed, 9 insertions(+), 5 deletions(-) | |
| diff --git a/kernel/common/array.rb b/kernel/common/array.rb | |
| index 7ff62b2..cc08e50 100644 | |
| --- a/kernel/common/array.rb | |
| +++ b/kernel/common/array.rb | |
| @@ -524,13 +524,17 @@ class Array | |
| # block is provided in which case the value of running it is | |
| # returned instead. | |
| def delete(obj) | |
| - key = undefined | |
| - i = to_iter | |
| - while i.next | |
| - set_index(i.index, key) if i.item == obj | |
| + if @total > 0 | |
| + key = undefined | |
| + i = to_iter | |
| + while i.next | |
| + set_index(i.index, key) if i.item == obj | |
| + end | |
| + deleted = @tuple.delete @start, @total, key | |
| + else | |
| + deleted = 0 | |
| end | |
| - deleted = @tuple.delete @start, @total, key | |
| if deleted > 0 | |
| @total -= deleted | |
| reallocate_shrink() | |
| -- | |
| 1.6.6.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment