polyfill 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +31 -2
- data/CONTRIBUTING.md +48 -17
- data/README.md +110 -80
- data/Rakefile +3 -1
- data/bin/console +3 -3
- data/lib/polyfill.rb +30 -19
- data/lib/polyfill/v2_4.rb +29 -12
- data/lib/polyfill/v2_4/array.rb +1 -1
- data/lib/polyfill/v2_4/array/instance.rb +3 -1
- data/lib/polyfill/v2_4/array/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/array/instance/sum.rb +17 -0
- data/lib/polyfill/v2_4/comparable.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance/clamp.rb +11 -13
- data/lib/polyfill/v2_4/dir.rb +1 -1
- data/lib/polyfill/v2_4/dir/class.rb +1 -1
- data/lib/polyfill/v2_4/dir/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/enumerable.rb +9 -0
- data/lib/polyfill/v2_4/enumerable/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +46 -0
- data/lib/polyfill/v2_4/enumerable/instance/sum.rb +52 -0
- data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +45 -0
- data/lib/polyfill/v2_4/enumerator/lazy.rb +11 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +25 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb +33 -0
- data/lib/polyfill/v2_4/file.rb +1 -1
- data/lib/polyfill/v2_4/file/class.rb +1 -1
- data/lib/polyfill/v2_4/file/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/float.rb +1 -1
- data/lib/polyfill/v2_4/float/instance.rb +3 -3
- data/lib/polyfill/v2_4/float/instance/ceil.rb +8 -10
- data/lib/polyfill/v2_4/float/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/float/instance/truncate.rb +8 -10
- data/lib/polyfill/v2_4/hash.rb +1 -1
- data/lib/polyfill/v2_4/hash/instance.rb +4 -4
- data/lib/polyfill/v2_4/hash/instance/compact.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/compact_e.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/transform_values.rb +6 -8
- data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +6 -8
- data/lib/polyfill/v2_4/i_p_addr.rb +9 -0
- data/lib/polyfill/v2_4/i_p_addr/instance.rb +13 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/equalequal.rb +27 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/lessthanequalgreaterthan.rb +27 -0
- data/lib/polyfill/v2_4/integer.rb +1 -1
- data/lib/polyfill/v2_4/integer/instance.rb +5 -5
- data/lib/polyfill/v2_4/integer/instance/ceil.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/digits.rb +5 -7
- data/lib/polyfill/v2_4/integer/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/round.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/truncate.rb +7 -9
- data/lib/polyfill/v2_4/io.rb +2 -2
- data/lib/polyfill/v2_4/io/class.rb +2 -2
- data/lib/polyfill/v2_4/io/class/foreach.rb +21 -33
- data/lib/polyfill/v2_4/io/class/readlines.rb +12 -13
- data/lib/polyfill/v2_4/io/instance.rb +6 -4
- data/lib/polyfill/v2_4/io/instance/each_line.rb +20 -33
- data/lib/polyfill/v2_4/io/instance/gets.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/lines.rb +54 -0
- data/lib/polyfill/v2_4/io/instance/readline.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/readlines.rb +12 -13
- data/lib/polyfill/v2_4/match_data.rb +1 -1
- data/lib/polyfill/v2_4/match_data/instance.rb +2 -2
- data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +5 -7
- data/lib/polyfill/v2_4/match_data/instance/values_at.rb +5 -7
- data/lib/polyfill/v2_4/numeric.rb +1 -1
- data/lib/polyfill/v2_4/numeric/instance.rb +6 -2
- data/lib/polyfill/v2_4/numeric/instance/clone.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/dup.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +5 -7
- data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +5 -7
- data/lib/polyfill/v2_4/object.rb +9 -0
- data/lib/polyfill/v2_4/object/instance.rb +11 -0
- data/lib/polyfill/v2_4/object/instance/clone.rb +29 -0
- data/lib/polyfill/v2_4/pathname.rb +9 -0
- data/lib/polyfill/v2_4/pathname/instance.rb +11 -0
- data/lib/polyfill/v2_4/pathname/instance/empty_q.rb +29 -0
- data/lib/polyfill/v2_4/regexp.rb +9 -0
- data/lib/polyfill/v2_4/regexp/instance.rb +11 -0
- data/lib/polyfill/v2_4/regexp/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string.rb +3 -1
- data/lib/polyfill/v2_4/string/class.rb +11 -0
- data/lib/polyfill/v2_4/string/class/new.rb +26 -0
- data/lib/polyfill/v2_4/string/instance.rb +12 -2
- data/lib/polyfill/v2_4/string/instance/casecmp_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/each_line.rb +17 -0
- data/lib/polyfill/v2_4/string/instance/lines.rb +55 -0
- data/lib/polyfill/v2_4/string/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/prepend.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/unpack1.rb +23 -0
- data/lib/polyfill/v2_4/string_io.rb +1 -1
- data/lib/polyfill/v2_4/string_io/instance.rb +4 -4
- data/lib/polyfill/v2_4/string_io/instance/each_line.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/gets.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readline.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readlines.rb +5 -7
- data/lib/polyfill/v2_4/symbol.rb +9 -0
- data/lib/polyfill/v2_4/symbol/instance.rb +15 -0
- data/lib/polyfill/v2_4/symbol/instance/casecmp_q.rb +25 -0
- data/lib/polyfill/v2_4/symbol/instance/match.rb +27 -0
- data/lib/polyfill/v2_4/symbol/instance/match_q.rb +17 -0
- data/lib/polyfill/version.rb +1 -1
- data/polyfill.gemspec +1 -0
- metadata +56 -3
data/lib/polyfill/v2_4/file.rb
CHANGED
@@ -9,14 +9,12 @@ module Polyfill
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
refine ::File.singleton_class do
|
13
|
+
include Method
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
data/lib/polyfill/v2_4/float.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'instance/ceil'
|
2
|
+
require_relative 'instance/floor'
|
3
|
+
require_relative 'instance/truncate'
|
4
4
|
|
5
5
|
module Polyfill
|
6
6
|
module V2_4
|
@@ -9,23 +9,21 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
|
11
11
|
if ndigits > 0
|
12
|
-
place = 10
|
12
|
+
place = 10**ndigits
|
13
13
|
(self * place).ceil / place.to_f
|
14
14
|
else
|
15
|
-
place = 10
|
16
|
-
(self
|
15
|
+
place = 10**-ndigits
|
16
|
+
(self / place).ceil * place
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
refine ::Float do
|
22
|
+
include Method
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
25
|
+
def self.included(base)
|
26
|
+
base.include Method
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -9,23 +9,21 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
|
11
11
|
if ndigits > 0
|
12
|
-
place = 10
|
12
|
+
place = 10**ndigits
|
13
13
|
(self * place).floor / place.to_f
|
14
14
|
else
|
15
|
-
place = 10
|
15
|
+
place = 10**-ndigits
|
16
16
|
(self / place).floor * place
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
refine ::Float do
|
22
|
+
include Method
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
25
|
+
def self.included(base)
|
26
|
+
base.include Method
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -9,23 +9,21 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
|
11
11
|
if ndigits > 0
|
12
|
-
place = 10
|
12
|
+
place = 10**ndigits
|
13
13
|
(self * place).truncate / place.to_f
|
14
14
|
else
|
15
|
-
place = 10
|
16
|
-
(self
|
15
|
+
place = 10**-ndigits
|
16
|
+
(self / place).truncate * place
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
refine ::Float do
|
22
|
+
include Method
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
25
|
+
def self.included(base)
|
26
|
+
base.include Method
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
data/lib/polyfill/v2_4/hash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative 'instance/compact'
|
2
|
+
require_relative 'instance/compact_e'
|
3
|
+
require_relative 'instance/transform_values'
|
4
|
+
require_relative 'instance/transform_values_e'
|
5
5
|
|
6
6
|
module Polyfill
|
7
7
|
module V2_4
|
@@ -9,14 +9,12 @@ module Polyfill
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
refine ::Hash do
|
13
|
+
include Method
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -9,14 +9,12 @@ module Polyfill
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
refine ::Hash do
|
13
|
+
include Method
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -6,7 +6,7 @@ module Polyfill
|
|
6
6
|
module Method
|
7
7
|
def transform_values
|
8
8
|
unless block_given?
|
9
|
-
return Enumerator.new(keys.size) do |yielder|
|
9
|
+
return ::Enumerator.new(keys.size) do |yielder|
|
10
10
|
each_with_object({}) do |(k, v), acc|
|
11
11
|
acc[k] = yielder.yield(v)
|
12
12
|
end
|
@@ -19,14 +19,12 @@ module Polyfill
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
refine ::Hash do
|
23
|
+
include Method
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def self.included(base)
|
27
|
+
base.include Method
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
@@ -6,7 +6,7 @@ module Polyfill
|
|
6
6
|
module Method
|
7
7
|
def transform_values!
|
8
8
|
unless block_given?
|
9
|
-
return Enumerator.new(keys.size) do |yielder|
|
9
|
+
return ::Enumerator.new(keys.size) do |yielder|
|
10
10
|
replace(each_with_object({}) do |(k, v), acc|
|
11
11
|
acc[k] = yielder.yield(v)
|
12
12
|
end)
|
@@ -19,14 +19,12 @@ module Polyfill
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
refine ::Hash do
|
23
|
+
include Method
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def self.included(base)
|
27
|
+
base.include Method
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_4
|
5
|
+
module IPAddr
|
6
|
+
module Instance
|
7
|
+
module Equalequal
|
8
|
+
module Method
|
9
|
+
def ==(*)
|
10
|
+
super
|
11
|
+
rescue
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
refine ::IPAddr do
|
17
|
+
include Method
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.include Method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_4
|
5
|
+
module IPAddr
|
6
|
+
module Instance
|
7
|
+
module Lessthanequalgreaterthan
|
8
|
+
module Method
|
9
|
+
def <=>(*)
|
10
|
+
super
|
11
|
+
rescue
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
refine ::IPAddr do
|
17
|
+
include Method
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.include Method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative 'instance/ceil'
|
2
|
+
require_relative 'instance/digits'
|
3
|
+
require_relative 'instance/floor'
|
4
|
+
require_relative 'instance/round'
|
5
|
+
require_relative 'instance/truncate'
|
6
6
|
|
7
7
|
module Polyfill
|
8
8
|
module V2_4
|
@@ -9,19 +9,17 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
return to_f if ndigits > 0
|
11
11
|
|
12
|
-
place = 10
|
13
|
-
(
|
12
|
+
place = 10**-ndigits
|
13
|
+
(to_f / place).ceil * place
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
refine ::Integer do
|
18
|
+
include Method
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
def self.included(base)
|
22
|
+
base.include Method
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -20,14 +20,12 @@ module Polyfill
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
refine ::Integer do
|
24
|
+
include Method
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
27
|
+
def self.included(base)
|
28
|
+
base.include Method
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -9,19 +9,17 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
return to_f if ndigits > 0
|
11
11
|
|
12
|
-
place = 10
|
13
|
-
(
|
12
|
+
place = 10**-ndigits
|
13
|
+
(to_f / place).floor * place
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
refine ::Integer do
|
18
|
+
include Method
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
def self.included(base)
|
22
|
+
base.include Method
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|