finishing_moves 1.0 → 1.0.1
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/README.md +4 -4
 - data/lib/finishing_moves/array.rb +6 -10
 - data/lib/finishing_moves/version.rb +1 -1
 - data/spec/array_spec.rb +10 -26
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7663bab15022e6b9d9c30f6884a0d807e8ae68b5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 225ba549fa8109fabd09d95813d2c0e6e5d83cf0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 97b0b49e565eb79d4bf2cdbcea46b37a4adc435a23832b9f0cf3c19372d75d559e6c21189931c343053819ce54cf8a136eaabb142cb52a84d5ac258fac2dffc6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 16a5d1358d8ae3e5eb1093b40053afdf015241f92b9cd7ca81eecd4abb56e97ab67771f130fceec2d8ae2d07d3fea05385e0b51c18fb85ce63692b6b3e98f144
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Finishing Moves
         
     | 
| 
       2 
2 
     | 
    
         
             
            [](https://rubygems.org/gems/finishing_moves)
         
     | 
| 
       3 
     | 
    
         
            -
            [](https://travis-ci.org/forgecrafted/finishing_moves)
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself performing contortions to achieve results that, honestly, **should feel more natural** given the language's design elegance. Finishing Moves is a collection of methods designed to assist in those "why is this awkward?" scenarios.
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -25,8 +25,8 @@ gem install 'finishing_moves' 
     | 
|
| 
       25 
25 
     | 
    
         
             
              - [`Array#to_hash_values`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_values) :boom:
         
     | 
| 
       26 
26 
     | 
    
         
             
              - [`Array#to_indexed_hash`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_indexed_hash)
         
     | 
| 
       27 
27 
     | 
    
         
             
              - [`Array#to_hash_keys`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_keys)
         
     | 
| 
       28 
     | 
    
         
            -
              - [`Array# 
     | 
| 
       29 
     | 
    
         
            -
              - [`Array# 
     | 
| 
      
 28 
     | 
    
         
            +
              - [`Array#to_sym_strict`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_strict) :new:
         
     | 
| 
      
 29 
     | 
    
         
            +
              - [`Array#to_sym_loose`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_loose) :new:
         
     | 
| 
       30 
30 
     | 
    
         
             
              - [`Enumerable#key_map`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map) :boom:
         
     | 
| 
       31 
31 
     | 
    
         
             
              - [`Enumerable#key_map_reduce`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map_reduce)
         
     | 
| 
       32 
32 
     | 
    
         
             
              - [`Hash#delete!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete)
         
     | 
| 
         @@ -66,7 +66,7 @@ gem install 'finishing_moves' 
     | 
|
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
            ### Ruby Version
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
            Tested against **`2.0.0` and above**. 
     | 
| 
      
 69 
     | 
    
         
            +
            Tested against **`2.0.0` and above**.
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
       71 
71 
     | 
    
         
             
            ## Development approach
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
         @@ -27,29 +27,25 @@ class Array 
     | 
|
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
28 
     | 
    
         
             
              alias_method :to_hash_as_keys, :to_hash_keys
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
              def  
     | 
| 
      
 30 
     | 
    
         
            +
              def to_sym_strict
         
     | 
| 
       31 
31 
     | 
    
         
             
                map { |x| x.to_sym }
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     | 
| 
       33 
     | 
    
         
            -
              alias_method :to_sym_hard, :to_sym
         
     | 
| 
       34 
33 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
              def  
     | 
| 
      
 34 
     | 
    
         
            +
              def to_sym_strict!
         
     | 
| 
       36 
35 
     | 
    
         
             
                map! { |x| x.to_sym }
         
     | 
| 
       37 
36 
     | 
    
         
             
              end
         
     | 
| 
       38 
     | 
    
         
            -
              alias_method :to_sym_hard!, :to_sym!
         
     | 
| 
       39 
37 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
              def  
     | 
| 
      
 38 
     | 
    
         
            +
              def to_sym_loose
         
     | 
| 
       41 
39 
     | 
    
         
             
                map do |x|
         
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
      
 40 
     | 
    
         
            +
                  if x.respond_to?(:to_sym)
         
     | 
| 
       43 
41 
     | 
    
         
             
                    x.to_sym
         
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
      
 42 
     | 
    
         
            +
                  else
         
     | 
| 
       45 
43 
     | 
    
         
             
                    x
         
     | 
| 
       46 
     | 
    
         
            -
                  rescue Exception
         
     | 
| 
       47 
     | 
    
         
            -
                    raise
         
     | 
| 
       48 
44 
     | 
    
         
             
                  end
         
     | 
| 
       49 
45 
     | 
    
         
             
                end
         
     | 
| 
       50 
46 
     | 
    
         
             
              end
         
     | 
| 
       51 
47 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
              def  
     | 
| 
      
 48 
     | 
    
         
            +
              def to_sym_loose!
         
     | 
| 
       53 
49 
     | 
    
         
             
                map! do |x|
         
     | 
| 
       54 
50 
     | 
    
         
             
                  begin
         
     | 
| 
       55 
51 
     | 
    
         
             
                    x.to_sym
         
     | 
    
        data/spec/array_spec.rb
    CHANGED
    
    | 
         @@ -99,45 +99,29 @@ describe Array do 
     | 
|
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         
             
              end
         
     | 
| 
       101 
101 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
              it '# 
     | 
| 
      
 102 
     | 
    
         
            +
              it '#to_sym_strict' do
         
     | 
| 
       103 
103 
     | 
    
         
             
                test = ['FOO', 'bar', :baz]
         
     | 
| 
       104 
     | 
    
         
            -
                expect(test. 
     | 
| 
      
 104 
     | 
    
         
            +
                expect(test.to_sym_strict).to eq [:FOO, :bar, :baz]
         
     | 
| 
       105 
105 
     | 
    
         
             
                expect(test).to eq ['FOO', 'bar', :baz]
         
     | 
| 
       106 
     | 
    
         
            -
                expect{ [1]. 
     | 
| 
       107 
     | 
    
         
            -
                # FinishingMoves::FalseClass#to_sym
         
     | 
| 
       108 
     | 
    
         
            -
                expect([false].to_sym).to eq [:false]
         
     | 
| 
      
 106 
     | 
    
         
            +
                expect{ [1].to_sym_strict }.to raise_error NoMethodError
         
     | 
| 
       109 
107 
     | 
    
         
             
              end
         
     | 
| 
       110 
108 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
              it '# 
     | 
| 
      
 109 
     | 
    
         
            +
              it '#to_sym_strict!' do
         
     | 
| 
       112 
110 
     | 
    
         
             
                test = ['FOO', 'bar', :baz]
         
     | 
| 
       113 
     | 
    
         
            -
                expect(test. 
     | 
| 
      
 111 
     | 
    
         
            +
                expect(test.to_sym_strict!).to eq [:FOO, :bar, :baz]
         
     | 
| 
       114 
112 
     | 
    
         
             
                expect(test).to eq [:FOO, :bar, :baz]
         
     | 
| 
       115 
     | 
    
         
            -
                expect{ [1]. 
     | 
| 
      
 113 
     | 
    
         
            +
                expect{ [1].to_sym_strict! }.to raise_error NoMethodError
         
     | 
| 
       116 
114 
     | 
    
         
             
              end
         
     | 
| 
       117 
115 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
              it '# 
     | 
| 
       119 
     | 
    
         
            -
                test = ['FOO', 'bar', :baz]
         
     | 
| 
       120 
     | 
    
         
            -
                expect(test.to_sym_hard).to eq [:FOO, :bar, :baz]
         
     | 
| 
       121 
     | 
    
         
            -
                expect(test).to eq ['FOO', 'bar', :baz]
         
     | 
| 
       122 
     | 
    
         
            -
                expect{ [1].to_sym_hard }.to raise_error NoMethodError
         
     | 
| 
       123 
     | 
    
         
            -
              end
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
              it '#to_sym_hard!' do
         
     | 
| 
       126 
     | 
    
         
            -
                test = ['FOO', 'bar', :baz]
         
     | 
| 
       127 
     | 
    
         
            -
                expect(test.to_sym_hard!).to eq [:FOO, :bar, :baz]
         
     | 
| 
       128 
     | 
    
         
            -
                expect(test).to eq [:FOO, :bar, :baz]
         
     | 
| 
       129 
     | 
    
         
            -
                expect{ [1].to_sym_hard! }.to raise_error NoMethodError
         
     | 
| 
       130 
     | 
    
         
            -
              end
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
              it '#to_sym_soft' do
         
     | 
| 
      
 116 
     | 
    
         
            +
              it '#to_sym_loose' do
         
     | 
| 
       133 
117 
     | 
    
         
             
                test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       134 
     | 
    
         
            -
                expect(test. 
     | 
| 
      
 118 
     | 
    
         
            +
                expect(test.to_sym_loose).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       135 
119 
     | 
    
         
             
                expect(test).to eq ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       136 
120 
     | 
    
         
             
              end
         
     | 
| 
       137 
121 
     | 
    
         | 
| 
       138 
     | 
    
         
            -
              it '# 
     | 
| 
      
 122 
     | 
    
         
            +
              it '#to_sym_loose!' do
         
     | 
| 
       139 
123 
     | 
    
         
             
                test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       140 
     | 
    
         
            -
                expect(test. 
     | 
| 
      
 124 
     | 
    
         
            +
                expect(test.to_sym_loose!).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       141 
125 
     | 
    
         
             
                expect(test).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
         
     | 
| 
       142 
126 
     | 
    
         
             
              end
         
     | 
| 
       143 
127 
     | 
    
         |