polyfill 0.1.0 → 0.2.0

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: e3143544ff61de6d188ad320ef3d55c40e189383
4
- data.tar.gz: 76b79543183719c9a8b6d4295ce14b430796b7d9
3
+ metadata.gz: 9d536c32a25db0ccb7bbbe70e7e921c35a97d95f
4
+ data.tar.gz: e8b0d4bf4c7ece75a844065d2407ce761e093564
5
5
  SHA512:
6
- metadata.gz: 13c1b0f61827fb5a028ac249363d7370abec0c7095d70f2741a8da1fee8d2cdf741c4dc64b0b09ba4873312248629d17e4bd7b489054f7682ac4aedeb4141b6b
7
- data.tar.gz: 2ca10336bf80e603552f15553cf33248cf48432c35d80f527d6811ef8e319c0f1a76b08815326909dc9f6360131896b7eaf2ddbef2028d9af264d1ce97b06199
6
+ metadata.gz: 4eb22154fb993d183068e2f8a7345b05a298b040d6911c2c4dbf71fbe5c524b505a2074067012d8d87b8afb90e83c50673a59b094a4c437058509c49fc98dca6
7
+ data.tar.gz: f2bacc5168680b5fa4a3b4a4c29d7e83cc8467d45fc4e78b9f551161ea0f898f72c8aa8a6e97f0e2951cf3516a6cf5dbafe5105bdea638c4fec2a71981171ad3
data/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # [0.2.0][]
2
+
3
+ ## Added
4
+
5
+ - v2.4 MatchData#named_captures
6
+ - v2.4 MatchData#values_at
7
+ - v2.4 Hash#compact
8
+ - v2.4 Hash#compact!
9
+ - v2.4 Hash#transform_values
10
+ - v2.4 Hash#transform_values!
11
+
12
+ ## Changes
13
+
14
+ - Modules are camel case instead of only uppercasing the first letter of the method name.
15
+ - Modules for predicate methods now end with `Q` instead of `__Q`.
16
+ - Modules for dangerous methods now end with `E` instead of `__E`.
17
+ - Methods will no longer attempt to fix `#respond_to?`, `#methods`, or `.instance_methods`. This will be revisited later with a more comprehensive solution.
18
+
19
+ # [0.1.0][] (2017-03-14)
20
+
21
+ - v2.4 Array#concat
22
+ - v2.4 Comparable#clamp
23
+ - v2.4 Float#ceil
24
+ - v2.4 Float#floor
25
+ - v2.4 Float#truncate
26
+ - v2.4 Integer#ceil
27
+ - v2.4 Integer#digits
28
+ - v2.4 Integer#floor
29
+ - v2.4 Integer#round
30
+ - v2.4 Integer#truncate
31
+ - v2.4 Numeric#finite?
32
+ - v2.4 Numeric#infinite?
33
+ - v2.4 String#concat?
34
+ - v2.4 String#prepend?
35
+
36
+ [0.2.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.1.0...v0.2.0
37
+ [0.1.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.0.0...v0.1.0
data/README.md CHANGED
@@ -32,7 +32,7 @@ See the [implementation table](#implementation-table) for specifics about what h
32
32
  Add it to your Gemfile:
33
33
 
34
34
  ```ruby
35
- gem 'polyfill', '0.1.0'
35
+ gem 'polyfill', '0.2.0'
36
36
  ```
37
37
 
38
38
  Or install it manually:
@@ -70,15 +70,16 @@ using Polyfill::V2_4::Array
70
70
  using Polyfill::V2_4::String
71
71
  ```
72
72
 
73
- To use a particular method, we can add it after the object. The first word
74
- of the method is uppercased. Predicate methods (ending with a question mark)
75
- have their question converted to a `__Q`. Dangerous methods (ending with an
76
- exclamation mark) have their exclamation replaced with `__E`.
73
+ To use a particular method, we can add it after the object. The method is
74
+ converted to camel case. Predicate methods (ending with a question mark)
75
+ have their question converted to a `Q`. Dangerous methods (ending with an
76
+ exclamation mark) have their exclamation replaced with `E`.
77
77
 
78
78
  ```ruby
79
79
  using Polyfill::V2_4::Array::Concat
80
- using Polyfill::V2_4::Dir::Empty__Q # :empty?
81
- using Polyfill::V2_4::Hash::Compact__E # :compact!
80
+ using Polyfill::V2_4::Dir::EmptyQ # :empty?
81
+ using Polyfill::V2_4::Hash::CompactE # :compact!
82
+ using Polyfill::V2_4::Hash::TransformValues # :transform_values!
82
83
  ```
83
84
 
84
85
  Any method can be accessed as a stand-alone module by adding `Method` to
@@ -119,10 +120,10 @@ method is only defined if the Ruby version requires it.
119
120
  | | #floor | Yes |
120
121
  | | #round | No |
121
122
  | | #truncate | Yes |
122
- | Hash | #compact | No |
123
- | | #compact! | No |
124
- | | #transform_values | No |
125
- | | #transform_values! | No |
123
+ | Hash | #compact | Yes |
124
+ | | #compact! | Yes |
125
+ | | #transform_values | Yes |
126
+ | | #transform_values! | Yes |
126
127
  | Integer | #ceil | Yes |
127
128
  | | #digits | Yes |
128
129
  | | #floor | Yes |
@@ -134,8 +135,8 @@ method is only defined if the Ruby version requires it.
134
135
  | | #readline | No |
135
136
  | | #readlines | No |
136
137
  | Kernel | #clone | No |
137
- | MatchData | #named_captures | No |
138
- | | #values_at | No |
138
+ | MatchData | #named_captures | Yes |
139
+ | | #values_at | Yes |
139
140
  | Module | #refine | No |
140
141
  | | .used_modules | No |
141
142
  | Numeric | #finite? | Yes |
data/lib/polyfill/v2_4.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'polyfill/v2_4/array'
2
2
  require 'polyfill/v2_4/comparable'
3
3
  require 'polyfill/v2_4/float'
4
+ require 'polyfill/v2_4/hash'
4
5
  require 'polyfill/v2_4/integer'
6
+ require 'polyfill/v2_4/match_data'
5
7
  require 'polyfill/v2_4/numeric'
6
8
  require 'polyfill/v2_4/string'
7
9
 
@@ -10,7 +12,9 @@ module Polyfill
10
12
  include Array
11
13
  include Comparable
12
14
  include Float
15
+ include Hash
13
16
  include Integer
17
+ include MatchData
14
18
  include Numeric
15
19
  include String
16
20
  end
@@ -15,8 +15,10 @@ module Polyfill
15
15
  end if RUBY_VERSION < '2.4.0'
16
16
  end
17
17
 
18
- refine ::Array do
19
- include Method
18
+ if RUBY_VERSION < '2.4.0'
19
+ refine ::Array do
20
+ include Method
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -12,22 +12,18 @@ module Polyfill
12
12
  return max if max < self
13
13
  self
14
14
  end if RUBY_VERSION < '2.4.0'
15
-
16
- def respond_to?(method, *)
17
- return true if method.to_sym == :clamp
18
-
19
- super
20
- end if RUBY_VERSION < '2.4.0'
21
15
  end
22
16
 
23
- refine ::Numeric do
24
- include Method
25
- end
26
- refine ::String do
27
- include Method
28
- end
29
- refine ::Time do
30
- include Method
17
+ if RUBY_VERSION < '2.4.0'
18
+ refine ::Numeric do
19
+ include Method
20
+ end
21
+ refine ::String do
22
+ include Method
23
+ end
24
+ refine ::Time do
25
+ include Method
26
+ end
31
27
  end
32
28
  end
33
29
  end
@@ -17,8 +17,10 @@ module Polyfill
17
17
  end if RUBY_VERSION < '2.4.0'
18
18
  end
19
19
 
20
- refine ::Float do
21
- include Method
20
+ if RUBY_VERSION < '2.4.0'
21
+ refine ::Float do
22
+ include Method
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -17,8 +17,10 @@ module Polyfill
17
17
  end if RUBY_VERSION < '2.4.0'
18
18
  end
19
19
 
20
- refine ::Float do
21
- include Method
20
+ if RUBY_VERSION < '2.4.0'
21
+ refine ::Float do
22
+ include Method
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -17,8 +17,10 @@ module Polyfill
17
17
  end if RUBY_VERSION < '2.4.0'
18
18
  end
19
19
 
20
- refine ::Float do
21
- include Method
20
+ if RUBY_VERSION < '2.4.0'
21
+ refine ::Float do
22
+ include Method
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -0,0 +1,15 @@
1
+ require 'polyfill/v2_4/hash/compact'
2
+ require 'polyfill/v2_4/hash/compact_e'
3
+ require 'polyfill/v2_4/hash/transform_values'
4
+ require 'polyfill/v2_4/hash/transform_values_e'
5
+
6
+ module Polyfill
7
+ module V2_4
8
+ module Hash
9
+ include Compact
10
+ include CompactE
11
+ include TransformValues
12
+ include TransformValuesE
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module Compact
5
+ module Method
6
+ def compact
7
+ reject { |_, v| v.nil? }
8
+ end if RUBY_VERSION < '2.4.0'
9
+ end
10
+
11
+ if RUBY_VERSION < '2.4.0'
12
+ refine ::Hash do
13
+ include Method
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module CompactE
5
+ module Method
6
+ def compact!
7
+ reject! { |_, v| v.nil? }
8
+ end if RUBY_VERSION < '2.4.0'
9
+ end
10
+
11
+ if RUBY_VERSION < '2.4.0'
12
+ refine ::Hash do
13
+ include Method
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module TransformValues
5
+ module Method
6
+ def transform_values
7
+ unless block_given?
8
+ return Enumerator.new(keys.size) do |yielder|
9
+ each_with_object({}) do |(k, v), acc|
10
+ acc[k] = yielder.yield(v)
11
+ end
12
+ end
13
+ end
14
+
15
+ each_with_object({}) do |(k, v), acc|
16
+ acc[k] = yield(v)
17
+ end
18
+ end if RUBY_VERSION < '2.4.0'
19
+ end
20
+
21
+ if RUBY_VERSION < '2.4.0'
22
+ refine ::Hash do
23
+ include Method
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module TransformValuesE
5
+ module Method
6
+ def transform_values!
7
+ unless block_given?
8
+ return Enumerator.new(keys.size) do |yielder|
9
+ replace(each_with_object({}) do |(k, v), acc|
10
+ acc[k] = yielder.yield(v)
11
+ end)
12
+ end
13
+ end
14
+
15
+ replace(each_with_object({}) do |(k, v), acc|
16
+ acc[k] = yield(v)
17
+ end)
18
+ end if RUBY_VERSION < '2.4.0'
19
+ end
20
+
21
+ if RUBY_VERSION < '2.4.0'
22
+ refine ::Hash do
23
+ include Method
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -13,8 +13,10 @@ module Polyfill
13
13
  end if RUBY_VERSION < '2.4.0'
14
14
  end
15
15
 
16
- refine ::Integer do
17
- include Method
16
+ if RUBY_VERSION < '2.4.0'
17
+ refine ::Integer do
18
+ include Method
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -17,16 +17,12 @@ module Polyfill
17
17
  end
18
18
  acc
19
19
  end if RUBY_VERSION < '2.4.0'
20
-
21
- def respond_to?(method, *)
22
- return true if method.to_sym == :digits
23
-
24
- super
25
- end if RUBY_VERSION < '2.4.0'
26
20
  end
27
21
 
28
- refine ::Integer do
29
- include Method
22
+ if RUBY_VERSION < '2.4.0'
23
+ refine ::Integer do
24
+ include Method
25
+ end
30
26
  end
31
27
  end
32
28
  end
@@ -13,8 +13,10 @@ module Polyfill
13
13
  end if RUBY_VERSION < '2.4.0'
14
14
  end
15
15
 
16
- refine ::Integer do
17
- include Method
16
+ if RUBY_VERSION < '2.4.0'
17
+ refine ::Integer do
18
+ include Method
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -16,8 +16,10 @@ module Polyfill
16
16
  end if RUBY_VERSION < '2.4.0'
17
17
  end
18
18
 
19
- refine ::Integer do
20
- include Method
19
+ if RUBY_VERSION < '2.4.0'
20
+ refine ::Integer do
21
+ include Method
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -13,8 +13,10 @@ module Polyfill
13
13
  end if RUBY_VERSION < '2.4.0'
14
14
  end
15
15
 
16
- refine ::Integer do
17
- include Method
16
+ if RUBY_VERSION < '2.4.0'
17
+ refine ::Integer do
18
+ include Method
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -0,0 +1,11 @@
1
+ require 'polyfill/v2_4/match_data/named_captures'
2
+ require 'polyfill/v2_4/match_data/values_at'
3
+
4
+ module Polyfill
5
+ module V2_4
6
+ module MatchData
7
+ include NamedCaptures
8
+ include ValuesAt
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module MatchData
4
+ module NamedCaptures
5
+ module Method
6
+ def named_captures
7
+ names.each_with_object({}) do |name, acc|
8
+ acc[name] = self[name]
9
+ end
10
+ end if RUBY_VERSION < '2.4.0'
11
+ end
12
+
13
+ if RUBY_VERSION < '2.4.0'
14
+ refine ::MatchData do
15
+ include Method
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module MatchData
4
+ module ValuesAt
5
+ module Method
6
+ def values_at(*indexes)
7
+ indexes.each_with_object([]) do |index, acc|
8
+ acc.push(self[index])
9
+ end
10
+ end if RUBY_VERSION < '2.4.0'
11
+ end
12
+
13
+ if RUBY_VERSION < '2.4.0'
14
+ refine ::MatchData do
15
+ include Method
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,11 +1,11 @@
1
- require 'polyfill/v2_4/numeric/finite__q'
2
- require 'polyfill/v2_4/numeric/infinite__q'
1
+ require 'polyfill/v2_4/numeric/finite_q'
2
+ require 'polyfill/v2_4/numeric/infinite_q'
3
3
 
4
4
  module Polyfill
5
5
  module V2_4
6
6
  module Numeric
7
- include Finite__Q
8
- include Infinite__Q
7
+ include FiniteQ
8
+ include InfiniteQ
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,19 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Numeric
4
+ module FiniteQ
5
+ module Method
6
+ def finite?
7
+ true
8
+ end if RUBY_VERSION < '2.4.0'
9
+ end
10
+
11
+ if RUBY_VERSION < '2.4.0'
12
+ refine ::Numeric do
13
+ include Method
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Numeric
4
+ module InfiniteQ
5
+ module Method
6
+ def infinite?
7
+ nil
8
+ end if RUBY_VERSION < '2.4.0'
9
+ end
10
+
11
+ if RUBY_VERSION < '2.4.0'
12
+ refine ::Numeric do
13
+ include Method
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -15,8 +15,10 @@ module Polyfill
15
15
  end if RUBY_VERSION < '2.4.0'
16
16
  end
17
17
 
18
- refine ::String do
19
- include Method
18
+ if RUBY_VERSION < '2.4.0'
19
+ refine ::String do
20
+ include Method
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -15,8 +15,10 @@ module Polyfill
15
15
  end if RUBY_VERSION < '2.4.0'
16
16
  end
17
17
 
18
- refine ::String do
19
- include Method
18
+ if RUBY_VERSION < '2.4.0'
19
+ refine ::String do
20
+ include Method
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,3 +1,3 @@
1
1
  module Polyfill
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyfill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - CONTRIBUTING.md
66
67
  - Gemfile
67
68
  - LICENSE.txt
@@ -79,15 +80,23 @@ files:
79
80
  - lib/polyfill/v2_4/float/ceil.rb
80
81
  - lib/polyfill/v2_4/float/floor.rb
81
82
  - lib/polyfill/v2_4/float/truncate.rb
83
+ - lib/polyfill/v2_4/hash.rb
84
+ - lib/polyfill/v2_4/hash/compact.rb
85
+ - lib/polyfill/v2_4/hash/compact_e.rb
86
+ - lib/polyfill/v2_4/hash/transform_values.rb
87
+ - lib/polyfill/v2_4/hash/transform_values_e.rb
82
88
  - lib/polyfill/v2_4/integer.rb
83
89
  - lib/polyfill/v2_4/integer/ceil.rb
84
90
  - lib/polyfill/v2_4/integer/digits.rb
85
91
  - lib/polyfill/v2_4/integer/floor.rb
86
92
  - lib/polyfill/v2_4/integer/round.rb
87
93
  - lib/polyfill/v2_4/integer/truncate.rb
94
+ - lib/polyfill/v2_4/match_data.rb
95
+ - lib/polyfill/v2_4/match_data/named_captures.rb
96
+ - lib/polyfill/v2_4/match_data/values_at.rb
88
97
  - lib/polyfill/v2_4/numeric.rb
89
- - lib/polyfill/v2_4/numeric/finite__q.rb
90
- - lib/polyfill/v2_4/numeric/infinite__q.rb
98
+ - lib/polyfill/v2_4/numeric/finite_q.rb
99
+ - lib/polyfill/v2_4/numeric/infinite_q.rb
91
100
  - lib/polyfill/v2_4/string.rb
92
101
  - lib/polyfill/v2_4/string/concat.rb
93
102
  - lib/polyfill/v2_4/string/prepend.rb
@@ -1,23 +0,0 @@
1
- module Polyfill
2
- module V2_4
3
- module Numeric
4
- module Finite__Q
5
- module Method
6
- def finite?
7
- true
8
- end if RUBY_VERSION < '2.4.0'
9
-
10
- def respond_to?(method, *)
11
- return true if method.to_sym == :finite?
12
-
13
- super
14
- end if RUBY_VERSION < '2.4.0'
15
- end
16
-
17
- refine ::Numeric do
18
- include Method
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module Polyfill
2
- module V2_4
3
- module Numeric
4
- module Infinite__Q
5
- module Method
6
- def infinite?
7
- nil
8
- end if RUBY_VERSION < '2.4.0'
9
-
10
- def respond_to?(method, *)
11
- return true if method.to_sym == :infinite?
12
-
13
- super
14
- end if RUBY_VERSION < '2.4.0'
15
- end
16
-
17
- refine ::Numeric do
18
- include Method
19
- end
20
- end
21
- end
22
- end
23
- end