ruby_extendsions 0.1.8.4 → 0.1.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,4 +2,26 @@
2
2
 
3
3
  simply install the gem:
4
4
 
5
- gem install ruby_extendsions
5
+ gem install ruby_extendsions
6
+
7
+ usage:
8
+
9
+ # Array#stringify_items! and Array#stringify_items
10
+ <pre>
11
+ arr, brr = [:a, [1,2,:cddd], :d, 1], [:b, [3,4,false], :b,2]
12
+ arr.stringify_items!
13
+ arr #=> ['a', ['1','2','cddd'], 'd', '1']
14
+ brr.stringify_items
15
+ brr #=> ["b", ["3", "4", "false"], "b", "2"]
16
+
17
+ </pre>
18
+
19
+ # Array#binary_search_index and Array#b_include?
20
+ # Array#compare_content
21
+ <pre>
22
+ foo, bar = [1,2,3], [3,2,1]
23
+ foo.compare_content bar
24
+ #=> true
25
+ </pre>
26
+
27
+ more ... please read source code.
@@ -57,27 +57,25 @@ module RubyExtendsions
57
57
  end
58
58
 
59
59
  # 二分查找返回数组index, 只限于可排序的元素
60
- def binary_search_index(e, l = 0, u = length - 1)
61
- return if l>u
62
- m=(l+u)/2
63
- return if !(e.class == self[m].class)
64
- begin
65
- e < self[m] ? u=m-1 : l=m+1
66
- e == self[m] ? m : binary_search_index(e,l,u)
67
- rescue
68
- return nil
69
- end
70
- end
71
-
72
- # 基于二分查找的include?
73
- def b_include? e
74
- begin
75
- temp = self.sort
76
- !temp.binary_search_index(e).nil?
77
- rescue
78
- return false
79
- end
80
- end
60
+ # def binary_search_index(e, l = 0, u = length - 1)
61
+ # return if l>u
62
+ # m=(l+u)/2
63
+ # begin
64
+ # e.to_s < self[m].to_s ? u=m-1 : l=m+1
65
+ # e == self[m] ? m : binary_search_index(e,l,u)
66
+ # rescue
67
+ # nil
68
+ # end
69
+ # end
70
+ #
71
+ # def b_include? e
72
+ # begin
73
+ # temp = self.sort_by{|i| i.to_s}
74
+ # !temp.binary_search_index(e).nil?
75
+ # rescue
76
+ # return false
77
+ # end
78
+ # end
81
79
 
82
80
  #比较两个数组内容相同,不包含顺序
83
81
  def compare_content com_arr
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby_extendsions"
5
- s.version = "0.1.8.4"
5
+ s.version = "0.1.8.5"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["blackanger"]
8
8
  s.email = ["blackanger.z@gmail.com"]
data/spec/array_spec.rb CHANGED
@@ -60,6 +60,13 @@ describe "RubyExtend::ArrayExtendsions" do
60
60
  arr.should be == ['a', ['1','2','cddd'], 'd', '1']
61
61
  brr.stringify_items.should be == ["b", ["3", "4", "false"], "b", "2"]
62
62
  brr.should be == [:b, [3,4,false], :b,2]
63
+
64
+ arr2 = [1,4,6,'sf', 'fs', 8, 2]
65
+ arr2.b_include?('sf').should be_true
66
+ arr2.b_include?(1).should be_true
67
+ arr2.b_include?('fs').should be_true
68
+ arr2.b_include?('8').should be_false
69
+
63
70
  end
64
71
 
65
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_extendsions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 111
4
+ hash: 109
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 8
10
- - 4
11
- version: 0.1.8.4
10
+ - 5
11
+ version: 0.1.8.5
12
12
  platform: ruby
13
13
  authors:
14
14
  - blackanger
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-20 00:00:00 +08:00
19
+ date: 2011-03-21 00:00:00 +08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency