y_support 2.0.17 → 2.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/y_support/core_ext/array/misc.rb +23 -1
 - data/lib/y_support/version.rb +1 -1
 - data/test/misc_test.rb +12 -3
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1ee5951ea1425d5aea67be99fe932b1c0cfdba9c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 39e951f5f04568856504cd32f621d82690282aab
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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
         
     | 
    
        data/lib/y_support/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-07-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     |