Skip to content
Browse files

add compare content without order method for Array

  • Loading branch information...
1 parent 1b4dcec commit ce3b6a51f0eb70bbb283064479bb870c8b53cf96 @ZhangHanDong committed Mar 19, 2011
Showing with 27 additions and 8 deletions.
  1. +1 −0 Gemfile
  2. +1 −0 lib/ruby_extendsions.rb
  3. +14 −6 lib/ruby_extendsions/array_extendsions.rb
  4. +3 −2 ruby_extendsions.gemspec
  5. +8 −0 spec/array_spec.rb
View
1 Gemfile
@@ -2,3 +2,4 @@ source :gemcutter
# Specify your gem's dependencies in ruby_extend.gemspec
gemspec
+
View
1 lib/ruby_extendsions.rb
@@ -1,3 +1,4 @@
+require 'set'
require 'ruby_extendsions/hash_extendsions'
require 'ruby_extendsions/array_extendsions'
View
20 lib/ruby_extendsions/array_extendsions.rb
@@ -1,10 +1,11 @@
module RubyExtendsions
module ArrayExtendsions
- def self.included(base)
- base.send :include, InstanceMethods
- base.send :extend, ClassMethods
- end
-
+ # def self.included(base)
+ # base.send :include, InstanceMethods
+ # base.send :extend, ClassMethods
+ # end
+ extend ActiveSupport::Concern
+
module InstanceMethods
def fill_nil(val)
self.inject([]) {|s, a| s << (a.nil? ? a=val : a)}
@@ -53,9 +54,16 @@ def binary_search_index(e, l = 0, u = length - 1)
end
# 基于二分查找的include?
- def b_include?(e)
+ def b_include? e
!self.binary_search_index(e).nil?
end
+
+ #比较两个数组内容相同
+ def compare_content com_arr
+ arr = Set.new self
+ com_arr = Set.new com_arr
+ return arr == com_arr
+ end
end#InstanceMethods
View
5 ruby_extendsions.gemspec
@@ -2,18 +2,19 @@
Gem::Specification.new do |s|
s.name = "ruby_extendsions"
- s.version = "0.1.8"
+ s.version = "0.1.8.1"
s.platform = Gem::Platform::RUBY
s.authors = ["blackanger"]
s.email = ["blackanger.z@gmail.com"]
s.homepage = "http://rubygems.org/gems/ruby_extendsions"
s.summary = "Ruby Extendsions For Hash"
- s.description = "Ruby Extendsions"
+ s.description = "Ruby Extendsions for rails 3.0.5+"
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"
+ s.add_development_dependency "rails", ">=3.0.5"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
View
8 spec/array_spec.rb
@@ -45,4 +45,12 @@
arr.b_include?(9999).should be_true
end
+ it "should be compare the elements between the two Array objects" do
+ arr, brr = [1,2,3], [3,2,1]
+ foo, bar = [1,2,3], [3,2,1,4]
+ arr.compare_content(brr).should be_true
+ foo.compare_content(bar).should be_false
+ (arr == brr ).should be_false
+ end
+
end

0 comments on commit ce3b6a5

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