Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Array#random

  • Loading branch information...
commit 51b75403ec94b594c3fb9347ae18e76a110f6c65 1 parent 51b44bd
Alex authored
5 lib/ruby_extendsions/array_extendsions.rb
View
@@ -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
3  ruby_extendsions.gemspec
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"
6 spec/array_spec.rb
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
Please sign in to comment.
Something went wrong with that request. Please try again.