Permalink
Browse files

modify

  • Loading branch information...
1 parent 7d19ca3 commit 8378cbdf1478542a7390f27fd47d7d7467006c1c @ZhangHanDong committed Dec 29, 2010
Showing with 25 additions and 2 deletions.
  1. +5 −1 lib/ruby_extendsions/array_extendsions.rb
  2. +1 −1 ruby_extendsions.gemspec
  3. +18 −0 spec/array_spec.rb
  4. +1 −0 spec/hash_spec.rb
@@ -7,7 +7,11 @@ def self.included(base)
module InstanceMethods
def fill_nil(val)
- self.inject([]){|s,a| s << a.to_s}
+ self.inject([]) {|s, a| s << (a.nil? ? a=val : a)}
+ end
+
+ def fill_nil!(val)
+ self.each_index { |i| self[i] ||= val }
end
end#InstanceMethods
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "ruby_extendsions"
- s.version = "0.1.2"
+ s.version = "0.1.3"
s.platform = Gem::Platform::RUBY
s.authors = ["blackanger"]
s.email = ["blackanger.z@gmail.com"]
View
@@ -0,0 +1,18 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "RubyExtend::ArrayExtendsions" do
+ before(:each) do
+ @arr1 = [1, 2, 3, nil, nil, nil]
+ end
+
+ it "A array data should have not fill_nil method if havn't use ruby_extend " do
+ @arr1.respond_to?("fill_nil").should eql false
+ end
+
+ it "A array include nil object data should be fill value" do
+ require 'ruby_extendsions'
+ @arr1.fill_nil!('')
+ @arr1.should eql([1,2,3,'','',''])
+ end
+
+end
View
@@ -13,4 +13,5 @@
require 'ruby_extendsions'
@hash1.hash_reverse.should eql({1=>:a, 2=>:b} )
end
+
end

0 comments on commit 8378cbd

Please sign in to comment.