Skip to content

Instantly share code, notes, and snippets.

@kronos
Created October 3, 2010 12:56
Show Gist options
  • Save kronos/608558 to your computer and use it in GitHub Desktop.
Save kronos/608558 to your computer and use it in GitHub Desktop.
From 4b95e77ae87ffe3878fd331c5aad51da9d6513ea Mon Sep 17 00:00:00 2001
From: Ivan Samsonov <[email protected]>
Date: Sun, 3 Oct 2010 16:51:33 +0400
Subject: [PATCH 1/2] Additional spec for Array#fill
---
spec/ruby/core/array/fill_spec.rb | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb
index d3724ef..3fd4b97 100644
--- a/spec/ruby/core/array/fill_spec.rb
+++ b/spec/ruby/core/array/fill_spec.rb
@@ -101,6 +101,7 @@ describe "Array#fill with (filler, index, length)" do
it "replaces all elements after the index if given an index and nil as a length" do
a = [1, 2, 3]
a.fill('x', 1, nil).should == [1, 'x', 'x']
+ a.fill('y', nil).should == ['y', 'y', 'y']
a.fill(1, nil){|i| i*2}.should == [1, 2, 4]
end
--
1.6.6.1
From 360d6a3d459edd597d9afb221e10bfa0ae36c933 Mon Sep 17 00:00:00 2001
From: Ivan Samsonov <[email protected]>
Date: Sun, 3 Oct 2010 16:55:45 +0400
Subject: [PATCH 2/2] Assume start is zero in case of block doesn't pass to Array#fill and second arg is nil
---
kernel/common/array.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/common/array.rb b/kernel/common/array.rb
index 8f206fe..e9c5411 100644
--- a/kernel/common/array.rb
+++ b/kernel/common/array.rb
@@ -683,7 +683,7 @@ class Array
right += size if right < 0
right += 1 unless one.exclude_end?
return self if right <= left # Nothing to modify
- elsif one != undefined
+ elsif one and one != undefined
left = Type.coerce_to one, Fixnum, :to_int
left += size if left < 0
left = 0 if left < 0
--
1.6.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment