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 +23 -1
- data/lib/ruby_extendsions/array_extendsions.rb +19 -21
- data/ruby_extendsions.gemspec +1 -1
- data/spec/array_spec.rb +7 -0
- metadata +4 -4
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
data/ruby_extendsions.gemspec
CHANGED
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:
|
4
|
+
hash: 109
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 8
|
10
|
-
-
|
11
|
-
version: 0.1.8.
|
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-
|
19
|
+
date: 2011-03-21 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|