Skip to content
Browse files

modify

  • Loading branch information...
1 parent 5780c24 commit 51b44bd40077af798d21a45488c03a921d70d75d @ZhangHanDong committed Jan 4, 2011
Showing with 21 additions and 1 deletion.
  1. +10 −0 lib/ruby_extendsions/array_extendsions.rb
  2. +1 −1 ruby_extendsions.gemspec
  3. +10 −0 spec/array_spec.rb
View
10 lib/ruby_extendsions/array_extendsions.rb
@@ -22,6 +22,16 @@ def format_mess_insert
s << t << '),'
end.chop
end
+
+ #whether the array is all nil item
+ # like arr = [nil,nil,nil,nil]
+ # arr.is_nil_all? #=> true
+ def is_nil_all?
+ b = true
+ self.each {|i| b = false if !i.nil? }
+ return b
+ end
+
end#InstanceMethods
module ClassMethods
View
2 ruby_extendsions.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "ruby_extendsions"
- s.version = "0.1.4"
+ s.version = "0.1.5"
s.platform = Gem::Platform::RUBY
s.authors = ["blackanger"]
s.email = ["blackanger.z@gmail.com"]
View
10 spec/array_spec.rb
@@ -4,10 +4,14 @@
before(:each) do
@arr1 = [1, 2, 3, nil, nil, nil]
@arr2 = [[1,2,3,nil,4],[4,5,6,nil,nil]]
+ @arr3 = [nil,nil,nil,nil]
+ @arr4 = [nil,nil,1,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
+ @arr2.respond_to?("format_mess_insert").should eql false
+ @arr2.respond_to?("is_nil_all?").should eql false
end
it "A array include nil object data should be fill value" do
@@ -21,4 +25,10 @@
@arr2.format_mess_insert.should eql("('1','2','3','','4'),('4','5','6','','')")
end
+ it "whether the Array is all nil item" do
+ require 'ruby_extendsions'
+ @arr3.is_nil_all?.should eql true
+ @arr4.is_nil_all?.should eql false
+ end
+
end

0 comments on commit 51b44bd

Please sign in to comment.
Something went wrong with that request. Please try again.