Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangHanDong committed Dec 29, 2010
1 parent 7d19ca3 commit 8378cbd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/ruby_extendsions/array_extendsions.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def self.included(base)


module InstanceMethods module InstanceMethods
def fill_nil(val) 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
end#InstanceMethods end#InstanceMethods


Expand Down
2 changes: 1 addition & 1 deletion ruby_extendsions.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "ruby_extendsions" s.name = "ruby_extendsions"
s.version = "0.1.2" s.version = "0.1.3"
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.authors = ["blackanger"] s.authors = ["blackanger"]
s.email = ["blackanger.z@gmail.com"] s.email = ["blackanger.z@gmail.com"]
Expand Down
18 changes: 18 additions & 0 deletions spec/array_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions spec/hash_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
require 'ruby_extendsions' require 'ruby_extendsions'
@hash1.hash_reverse.should eql({1=>:a, 2=>:b} ) @hash1.hash_reverse.should eql({1=>:a, 2=>:b} )
end end

end end

0 comments on commit 8378cbd

Please sign in to comment.