y_support 2.0.17 → 2.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10a3213c28c3bf0979906e9cb5ab9f68ee4eafbf
4
- data.tar.gz: 63c23e808be62cd1490384e7a3cf6e7939400dbe
3
+ metadata.gz: 1ee5951ea1425d5aea67be99fe932b1c0cfdba9c
4
+ data.tar.gz: 39e951f5f04568856504cd32f621d82690282aab
5
5
  SHA512:
6
- metadata.gz: d321fb398e16a46bf622fb2f1a2db07c4b5a1da735c1a5c9fb72e86373619568662e5dc9e4327bf9350e7eb15471f6dca4c56549f30a519582331a1e95e9942e
7
- data.tar.gz: bef7becb10032eba4142e1dcdd7b4c2dfa4d7bcc1f54fa0361f1306100985dc2fc959fcd4f4a4ac003a6dbbdbee2b490e4839c858894ecd16121a8ddb524affc
6
+ metadata.gz: 8ee78b2a4107db323c83d89681b91a70dc2fe0e787de831404c8944181e12dc45b0cfcc44c148f728bc2dad317c6443d2cf50ee5f53a7c85977f50405fe36978
7
+ data.tar.gz: 45d4a42769e648d2eeeedc60d33121fc560069fbe4d481ac3d33c353979833e19a8a9ebd1f5f4c029b7ad4b7291dd9682a2cff3030ac1168b5feab1f1d25eb3d
@@ -11,7 +11,29 @@ class Array
11
11
  a.merge( { e[0] => tail.size >= 2 ? tail : tail[0] } )
12
12
  }
13
13
  end
14
-
14
+
15
+
16
+ # Zips this array with another collection into a hash. If a block is given,
17
+ # it is applied to each element of the array to get the hash values.
18
+ #
19
+ def zip_to_hash collection=nil
20
+ if block_given? then
21
+ fail ArgumentError, "Argument not allowed if block given!" unless
22
+ collection.nil?
23
+ Hash[ zip( collection.map { |e| yield e } ) ]
24
+ else
25
+ fail ArgumentError "A second collection expected as an argument!" unless
26
+ collection.respond_to? :each
27
+ Hash[ zip( collection ) ]
28
+ end
29
+ end
30
+
31
+ # Zips this array with another collection into a hash.
32
+ #
33
+ def >> collection
34
+ zip_to_hash collection
35
+ end
36
+
15
37
  # Allows style &[ function, *arguments ]
16
38
  #
17
39
  def to_proc
@@ -1,3 +1,3 @@
1
1
  module YSupport
2
- VERSION = "2.0.17"
2
+ VERSION = "2.0.18"
3
3
  end
data/test/misc_test.rb CHANGED
@@ -62,16 +62,25 @@ describe Array do
62
62
  before do
63
63
  require 'y_support/core_ext/array'
64
64
  end
65
-
65
+
66
66
  it "has #to_hash" do
67
67
  assert_equal( {a: :b, c: :d}, [[:a, :b],[:c, :d]].to_hash )
68
68
  assert_equal( {k: :kokot, p: :pica}, [[:k, :o, :kokot], [:p, :i, :pica]].to_hash(2) )
69
69
  end
70
-
70
+
71
+ it "has #zip_to_hash" do
72
+ assert_equal( {a: 1, b: 2}, [:a, :b].zip_to_hash( [1, 2] ) )
73
+ assert_equal( {a: "a"}, [:a].zip_to_hash( &:to_s ) )
74
+ end
75
+
76
+ it "has #>>" do
77
+ assert_equal( {a: 1, b: 2}, [:a, :b] >> [1, 2] )
78
+ end
79
+
71
80
  it "has #to_proc in style &[function, *args]" do
72
81
  assert_equal [2, 3], [1, 2].map( &[:+, 1] )
73
82
  end
74
-
83
+
75
84
  it "has #push/pop_ordered/named" do
76
85
  a = [1, 2, foo: 3]
77
86
  a.pop_named( :foo ).must_equal 3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.17
4
+ version: 2.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport