polyfill 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3143544ff61de6d188ad320ef3d55c40e189383
4
+ data.tar.gz: 76b79543183719c9a8b6d4295ce14b430796b7d9
5
+ SHA512:
6
+ metadata.gz: 13c1b0f61827fb5a028ac249363d7370abec0c7095d70f2741a8da1fee8d2cdf741c4dc64b0b09ba4873312248629d17e4bd7b489054f7682ac4aedeb4141b6b
7
+ data.tar.gz: 2ca10336bf80e603552f15553cf33248cf48432c35d80f527d6811ef8e319c0f1a76b08815326909dc9f6360131896b7eaf2ddbef2028d9af264d1ce97b06199
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.0
4
+ - 2.3.3
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,59 @@
1
+ ## Contributing
2
+
3
+ 1. [Fork](#fork)
4
+ 2. [Tests](#tests)
5
+ 3. [Code](#code)
6
+ 4. [Push and Submit](#push-and-submit)
7
+ 5. [Refine Until Merged](#refine-until-merged)
8
+
9
+ ### Fork
10
+
11
+ [Fork](https://github.com/AaronLasseigne/polyfill/fork) the repo.
12
+
13
+ ### Tests
14
+
15
+ The goal is to produce code that is identical to the real method. One
16
+ of the best places to find examples is the
17
+ [Ruby Spec Suite](https://github.com/ruby/spec). If tests exist there,
18
+ please copy them out and change them from MSpec to RSpec. Newer
19
+ methods may not be available in which case you'll have to add your
20
+ own tests. If the feature is new then you'll need to test every aspect
21
+ of it.
22
+
23
+ If this is a change that adds to an existing feature make sure to have
24
+ a basic test of the old functionality and then test all of the new
25
+ functionality.
26
+
27
+ Looking over an existing test or two should give you an idea of what
28
+ to do.
29
+
30
+ ### Code
31
+
32
+ The directory structure follows the module structure. Files are added
33
+ (`require` and `include`) one directly level up from their location.
34
+ This help keep everything segmented and stops there from being a
35
+ single top level file with a ton of `require` statements.
36
+
37
+ The structure is formulaic so looking through an existing example
38
+ or two should clarify what to do. If you're not sure how to proceed,
39
+ please reach out and we'll figure it out.
40
+
41
+ Partial implementations of features are welcome as long as they
42
+ bring value. Generally it's only ok to leave out part of the feature
43
+ when that part is very hard and/or secondary to the primary
44
+ functionality. What constitutes "value", "hard", and what gets
45
+ accepted may seem a bit arbitrary. If you're unsure, please reach out
46
+ and we'll discuss. I'd hate to see a bunch of work done only to get
47
+ rejected.
48
+
49
+ ### Push and Submit
50
+
51
+ Push your branch up to your fork. Submit a pull request via
52
+ GitHub.
53
+
54
+ ### Refine Until Merged
55
+
56
+ There are weird edge cases and particulars that might need to be
57
+ changed. Don't worry if you get a lot of comments on your pull
58
+ request. That's why we have code reviews. People miss things and more
59
+ eyes catch more issues. After everything is fixed: VICTORY!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in polyfill.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Aaron Lasseigne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # Polyfill
2
+
3
+ [![Build](https://travis-ci.org/AaronLasseigne/polyfill.svg?branch=master)](https://travis-ci.org/AaronLasseigne/polyfill)
4
+
5
+ Polyfill implements newer Ruby features into older versions. If the Ruby
6
+ version already supports the polyfill then calling it does nothing. This is
7
+ designed to allow gem maintainers to use newer methods and gain their
8
+ advantages while retaining backwards compatibility. It can also be used for
9
+ code that would like newer features but is not completely ready to upgrade
10
+ Ruby versions. The polyfills are built using refinements so there is **no
11
+ monkey patching** that may cause issues outside of your use.
12
+
13
+ Right now the only update is from 2.3 to 2.4 however the goal is to go all the way back to 2.0 (when refinements were introduced). Additionally, core methods are being focused on but stdlib will eventually be added.
14
+
15
+ - [Caveat Emptor](#caveat-emptor)
16
+ - [Installation](#installation)
17
+ - [Goals](#goals)
18
+ - [Usage](#usage)
19
+ - [Implementation Table](#implementation-table)
20
+
21
+ ## Caveat Emptor
22
+
23
+ Not all features can be perfectly implemented. This is a best effort
24
+ implementation but it's best to always test thoroughly across versions.
25
+ This project is also currently pre-1.0. Breaking changes may occur on
26
+ any release. Once a stable API is built it will be moved to 1.0.0.
27
+
28
+ See the [implementation table](#implementation-table) for specifics about what has been implemented.
29
+
30
+ ## Installation
31
+
32
+ Add it to your Gemfile:
33
+
34
+ ```ruby
35
+ gem 'polyfill', '0.1.0'
36
+ ```
37
+
38
+ Or install it manually:
39
+
40
+ ```sh
41
+ $ gem install polyfill
42
+ ```
43
+
44
+ This project uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
45
+
46
+ ## Goals
47
+
48
+ 1. Features should ideally mimic the true behavior (including bugs).
49
+ 2. Features should not significantly burden the runtime.
50
+ 3. Keep everything modular so users can be specific or broad in their usage.
51
+
52
+ ## Usage
53
+
54
+ To use all updates:
55
+
56
+ ```ruby
57
+ using Polyfill
58
+ ```
59
+
60
+ To use all updates up to V2_4:
61
+
62
+ ```ruby
63
+ using Polyfill::V2_4
64
+ ```
65
+
66
+ To use all updates for a particular object, add it to the end:
67
+
68
+ ```ruby
69
+ using Polyfill::V2_4::Array
70
+ using Polyfill::V2_4::String
71
+ ```
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`.
77
+
78
+ ```ruby
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!
82
+ ```
83
+
84
+ Any method can be accessed as a stand-alone module by adding `Method` to
85
+ the end:
86
+
87
+ ```ruby
88
+ include Polyfill::V2_4::Comparable::Clamp::Method
89
+ ```
90
+
91
+ **A note about modules:** Prior to 2.4, refinements do not work on modules.
92
+ This means modules like `Comparable` will apply the refinement to all child
93
+ classes. Anything custom classes that inherit from `Comparable` will be
94
+ unaffected by the refinement. In cases like this you can use `include` as
95
+ demonstrated above to pull in the needed method. Just like always, the
96
+ method is only defined if the Ruby version requires it.
97
+
98
+
99
+ ## Implementation Table
100
+
101
+ ### 2.3 to 2.4
102
+
103
+ | Object | Method | Implemented | Notes |
104
+ | ---------------- | ---------------------- | ----------- | ----- |
105
+ | Array | #concat | Yes |
106
+ | | #max | No |
107
+ | | #min | No |
108
+ | | #pack | No |
109
+ | | #sum | No |
110
+ | Comparable | #clamp | Yes |
111
+ | Dir | #empty? | No |
112
+ | Enumerable | #chunk | No |
113
+ | | #sum | No |
114
+ | | #uniq | No |
115
+ | Enumerator::Lazy | #chunk_while | No |
116
+ | | #uniq | No |
117
+ | File | #empty? | No |
118
+ | Float | #ceil | Yes |
119
+ | | #floor | Yes |
120
+ | | #round | No |
121
+ | | #truncate | Yes |
122
+ | Hash | #compact | No |
123
+ | | #compact! | No |
124
+ | | #transform_values | No |
125
+ | | #transform_values! | No |
126
+ | Integer | #ceil | Yes |
127
+ | | #digits | Yes |
128
+ | | #floor | Yes |
129
+ | | #round | Yes |
130
+ | | #truncate | Yes |
131
+ | IO | #each_line | No |
132
+ | | .foreach | No |
133
+ | | #gets | No |
134
+ | | #readline | No |
135
+ | | #readlines | No |
136
+ | Kernel | #clone | No |
137
+ | MatchData | #named_captures | No |
138
+ | | #values_at | No |
139
+ | Module | #refine | No |
140
+ | | .used_modules | No |
141
+ | Numeric | #finite? | Yes |
142
+ | | #infinite? | Yes |
143
+ | Rational | #round | No |
144
+ | Regexp | #match? | No |
145
+ | String | #capitalize | No |
146
+ | | #capitalize! | No |
147
+ | | #casecmp? | No |
148
+ | | #concat | Yes |
149
+ | | #downcase | No |
150
+ | | #downcase! | No |
151
+ | | #each_line | No |
152
+ | | #lines | No |
153
+ | | #match? | No |
154
+ | | .new | No |
155
+ | | #prepend | Yes |
156
+ | | #swapcase | No |
157
+ | | #swapcase! | No |
158
+ | | #unpack1 | No |
159
+ | | #upcase | No |
160
+ | | #upcase! | No |
161
+ | StringIO | #each_line | No |
162
+ | | #gets | No |
163
+ | | #readline | No |
164
+ | | #readlines | No |
165
+ | Symbol | #capitalize | No |
166
+ | | #capitalize! | No |
167
+ | | #casecmp? | No |
168
+ | | #downcase | No |
169
+ | | #downcase! | No |
170
+ | | #match | No |
171
+ | | #match? | No |
172
+ | | #swapcase | No |
173
+ | | #swapcase! | No |
174
+ | | #upcase | No |
175
+ | | #upcase! | No |
176
+ | Thread | #report\_on\_exception | No |
177
+ | | .report\_on\_exception | No |
178
+ | TracePoint | #callee_id | No |
179
+ | Warning | #warn | No |
180
+
181
+ ## Contributing
182
+
183
+ Bug reports and pull requests are welcome on GitHub at https://github.com/AaronLasseigne/polyfill.
184
+ Please read the [contributing file](CONTRIBUTING.md) prior to pull requests.
185
+
186
+ ## Credits
187
+
188
+ Polyfill is licensed under the [MIT License](LICENSE.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "polyfill"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/polyfill.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'polyfill/version'
2
+ require 'polyfill/v2_4'
3
+
4
+ module Polyfill
5
+ include V2_4
6
+ end
@@ -0,0 +1,17 @@
1
+ require 'polyfill/v2_4/array'
2
+ require 'polyfill/v2_4/comparable'
3
+ require 'polyfill/v2_4/float'
4
+ require 'polyfill/v2_4/integer'
5
+ require 'polyfill/v2_4/numeric'
6
+ require 'polyfill/v2_4/string'
7
+
8
+ module Polyfill
9
+ module V2_4
10
+ include Array
11
+ include Comparable
12
+ include Float
13
+ include Integer
14
+ include Numeric
15
+ include String
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'polyfill/v2_4/array/concat'
2
+
3
+ module Polyfill
4
+ module V2_4
5
+ module Array
6
+ include Concat
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Array
4
+ module Concat
5
+ module Method
6
+ def concat(*others)
7
+ return super if others.length == 1
8
+
9
+ acc = [].concat(self)
10
+ others.each do |other|
11
+ acc.concat(other)
12
+ end
13
+
14
+ replace(acc)
15
+ end if RUBY_VERSION < '2.4.0'
16
+ end
17
+
18
+ refine ::Array do
19
+ include Method
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'polyfill/v2_4/comparable/clamp'
2
+
3
+ module Polyfill
4
+ module V2_4
5
+ module Comparable
6
+ include Clamp
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Comparable
4
+ module Clamp
5
+ module Method
6
+ def clamp(min, max)
7
+ if min > max
8
+ raise ArgumentError, 'min argument must be smaller than max argument'
9
+ end
10
+
11
+ return min if min > self
12
+ return max if max < self
13
+ self
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
+ end
22
+
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
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ require 'polyfill/v2_4/float/ceil'
2
+ require 'polyfill/v2_4/float/floor'
3
+ require 'polyfill/v2_4/float/truncate'
4
+
5
+ module Polyfill
6
+ module V2_4
7
+ module Float
8
+ include Ceil
9
+ include Floor
10
+ include Truncate
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
4
+ module Ceil
5
+ module Method
6
+ def ceil(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+
10
+ if ndigits > 0
11
+ place = 10 ** ndigits
12
+ (self * place).ceil / place.to_f
13
+ else
14
+ place = 10 ** -ndigits
15
+ (self.to_f / place).ceil * place
16
+ end
17
+ end if RUBY_VERSION < '2.4.0'
18
+ end
19
+
20
+ refine ::Float do
21
+ include Method
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
4
+ module Floor
5
+ module Method
6
+ def floor(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+
10
+ if ndigits > 0
11
+ place = 10 ** ndigits
12
+ (self * place).floor / place.to_f
13
+ else
14
+ place = 10 ** -ndigits
15
+ (self / place).floor * place
16
+ end
17
+ end if RUBY_VERSION < '2.4.0'
18
+ end
19
+
20
+ refine ::Float do
21
+ include Method
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
4
+ module Truncate
5
+ module Method
6
+ def truncate(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+
10
+ if ndigits > 0
11
+ place = 10 ** ndigits
12
+ (self * place).truncate / place.to_f
13
+ else
14
+ place = 10 ** -ndigits
15
+ (self.to_f / place).truncate * place
16
+ end
17
+ end if RUBY_VERSION < '2.4.0'
18
+ end
19
+
20
+ refine ::Float do
21
+ include Method
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'polyfill/v2_4/integer/ceil'
2
+ require 'polyfill/v2_4/integer/digits'
3
+ require 'polyfill/v2_4/integer/floor'
4
+ require 'polyfill/v2_4/integer/round'
5
+ require 'polyfill/v2_4/integer/truncate'
6
+
7
+ module Polyfill
8
+ module V2_4
9
+ module Integer
10
+ include Ceil
11
+ include Digits
12
+ include Floor
13
+ include Round
14
+ include Truncate
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Ceil
5
+ module Method
6
+ def ceil(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+ return to_f if ndigits > 0
10
+
11
+ place = 10 ** -ndigits
12
+ (self.to_f / place).ceil * place
13
+ end if RUBY_VERSION < '2.4.0'
14
+ end
15
+
16
+ refine ::Integer do
17
+ include Method
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Digits
5
+ module Method
6
+ def digits(base = 10)
7
+ base = base.to_int
8
+ raise Math::DomainError, 'out of domain' if self < 0
9
+ raise ArgumentError, 'negative radix' if base < 0
10
+ raise ArgumentError, "invalid radix #{base}" if base < 2
11
+
12
+ acc = []
13
+ remainder = self
14
+ while remainder > 0
15
+ remainder, value = remainder.divmod(base)
16
+ acc.push(value)
17
+ end
18
+ acc
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
+ end
27
+
28
+ refine ::Integer do
29
+ include Method
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Floor
5
+ module Method
6
+ def floor(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+ return to_f if ndigits > 0
10
+
11
+ place = 10 ** -ndigits
12
+ (self.to_f / place).floor * place
13
+ end if RUBY_VERSION < '2.4.0'
14
+ end
15
+
16
+ refine ::Integer do
17
+ include Method
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Round
5
+ module Method
6
+ def round(ndigits = 0, half: nil)
7
+ unless [nil, :down, :even, :up, 'down', 'even', 'up'].include?(half)
8
+ raise ArgumentError, "invalid rounding mode: #{half}"
9
+ end
10
+ ndigits = ndigits.to_int
11
+ return super() if ndigits == 0
12
+ return to_f if ndigits > 0
13
+
14
+ place = 10 ** -ndigits
15
+ (self.to_f / place).round * place
16
+ end if RUBY_VERSION < '2.4.0'
17
+ end
18
+
19
+ refine ::Integer do
20
+ include Method
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Truncate
5
+ module Method
6
+ def truncate(ndigits = 0)
7
+ ndigits = ndigits.to_int
8
+ return super() if ndigits == 0
9
+ return to_f if ndigits > 0
10
+
11
+ place = 10 ** -ndigits
12
+ (self.to_f / place).truncate * place
13
+ end if RUBY_VERSION < '2.4.0'
14
+ end
15
+
16
+ refine ::Integer do
17
+ include Method
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'polyfill/v2_4/numeric/finite__q'
2
+ require 'polyfill/v2_4/numeric/infinite__q'
3
+
4
+ module Polyfill
5
+ module V2_4
6
+ module Numeric
7
+ include Finite__Q
8
+ include Infinite__Q
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,11 @@
1
+ require 'polyfill/v2_4/string/concat'
2
+ require 'polyfill/v2_4/string/prepend'
3
+
4
+ module Polyfill
5
+ module V2_4
6
+ module String
7
+ include Concat
8
+ include Prepend
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module String
4
+ module Concat
5
+ module Method
6
+ def concat(*others)
7
+ return super if others.length == 1
8
+
9
+ acc = '' << self
10
+ others.each do |other|
11
+ acc << other
12
+ end
13
+
14
+ replace(acc)
15
+ end if RUBY_VERSION < '2.4.0'
16
+ end
17
+
18
+ refine ::String do
19
+ include Method
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module String
4
+ module Prepend
5
+ module Method
6
+ def prepend(*others)
7
+ return super if others.length == 1
8
+
9
+ acc = '' << self
10
+ others.reverse_each do |other|
11
+ acc.prepend(other)
12
+ end
13
+
14
+ replace(acc)
15
+ end if RUBY_VERSION < '2.4.0'
16
+ end
17
+
18
+ refine ::String do
19
+ include Method
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Polyfill
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/polyfill.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'polyfill/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'polyfill'
8
+ spec.version = Polyfill::VERSION
9
+ spec.authors = ['Aaron Lasseigne']
10
+ spec.email = ['aaron.lasseigne@gmail.com']
11
+
12
+ spec.summary = 'Adds newer Ruby methods to older versions.'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 2.3'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.14'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.5'
28
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polyfill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Lasseigne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ description:
56
+ email:
57
+ - aaron.lasseigne@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CONTRIBUTING.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/polyfill.rb
73
+ - lib/polyfill/v2_4.rb
74
+ - lib/polyfill/v2_4/array.rb
75
+ - lib/polyfill/v2_4/array/concat.rb
76
+ - lib/polyfill/v2_4/comparable.rb
77
+ - lib/polyfill/v2_4/comparable/clamp.rb
78
+ - lib/polyfill/v2_4/float.rb
79
+ - lib/polyfill/v2_4/float/ceil.rb
80
+ - lib/polyfill/v2_4/float/floor.rb
81
+ - lib/polyfill/v2_4/float/truncate.rb
82
+ - lib/polyfill/v2_4/integer.rb
83
+ - lib/polyfill/v2_4/integer/ceil.rb
84
+ - lib/polyfill/v2_4/integer/digits.rb
85
+ - lib/polyfill/v2_4/integer/floor.rb
86
+ - lib/polyfill/v2_4/integer/round.rb
87
+ - lib/polyfill/v2_4/integer/truncate.rb
88
+ - lib/polyfill/v2_4/numeric.rb
89
+ - lib/polyfill/v2_4/numeric/finite__q.rb
90
+ - lib/polyfill/v2_4/numeric/infinite__q.rb
91
+ - lib/polyfill/v2_4/string.rb
92
+ - lib/polyfill/v2_4/string/concat.rb
93
+ - lib/polyfill/v2_4/string/prepend.rb
94
+ - lib/polyfill/version.rb
95
+ - polyfill.gemspec
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '2.3'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Adds newer Ruby methods to older versions.
120
+ test_files: []