Permalink
Browse files

Add Array#random

  • Loading branch information...
1 parent 51b44bd commit 51b75403ec94b594c3fb9347ae18e76a110f6c65 @ZhangHanDong committed Jan 7, 2011
Showing with 12 additions and 2 deletions.
  1. +5 −0 lib/ruby_extendsions/array_extendsions.rb
  2. +1 −2 ruby_extendsions.gemspec
  3. +6 −0 spec/array_spec.rb
@@ -32,6 +32,11 @@ def is_nil_all?
return b
end
+ #Random return an Array item
+ def random
+ return self[rand(self.size)]
+ end
+
end#InstanceMethods
module ClassMethods
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "ruby_extendsions"
- s.version = "0.1.5"
+ s.version = "0.1.6"
s.platform = Gem::Platform::RUBY
s.authors = ["blackanger"]
s.email = ["blackanger.z@gmail.com"]
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "ruby_extendsions"
-
s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rspec"
View
@@ -31,4 +31,10 @@
@arr4.is_nil_all?.should eql false
end
+ it "should can random return an Array item" do
+ require 'ruby_extendsions'
+ arr = [1,2,3,4,5,6,7,8]
+ arr.random.should be_a_kind_of(Fixnum)
+ end
+
end

0 comments on commit 51b7540

Please sign in to comment.