ruby_extendsions 0.1.8.3 → 0.1.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,18 @@ module RubyExtendsions
44
44
  def random
45
45
  return self[rand(self.size)]
46
46
  end
47
+
48
+ # 把数组元素全部转换为字符串。
49
+ def stringify_items!
50
+ self.each_with_index do |item, i|
51
+ item.is_a?(Array) ? item.stringify_items! : self[i] = item.to_s
52
+ end
53
+ end
54
+
55
+ def stringify_items
56
+ Marshal.load(Marshal.dump(self)).stringify_items!
57
+ end
58
+
47
59
  # 二分查找返回数组index, 只限于可排序的元素
48
60
  def binary_search_index(e, l = 0, u = length - 1)
49
61
  return if l>u
@@ -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.3"
5
+ s.version = "0.1.8.4"
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
@@ -53,4 +53,13 @@ describe "RubyExtend::ArrayExtendsions" do
53
53
  (arr == brr ).should be_false
54
54
  end
55
55
 
56
+ it "should be change to string" do
57
+ arr, brr = [:a, [1,2,:cddd], :d, 1], [:b, [3,4,false], :b,2]
58
+ arr.stringify_items!
59
+ arr.should_not be == [:a, [1,2,:cddd], :d, 1]
60
+ arr.should be == ['a', ['1','2','cddd'], 'd', '1']
61
+ brr.stringify_items.should be == ["b", ["3", "4", "false"], "b", "2"]
62
+ brr.should be == [:b, [3,4,false], :b,2]
63
+ end
64
+
56
65
  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: 97
4
+ hash: 111
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 8
10
- - 3
11
- version: 0.1.8.3
10
+ - 4
11
+ version: 0.1.8.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - blackanger