polyfill 0.2.0 → 0.3.0
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/CHANGELOG.md +23 -1
- data/README.md +30 -44
- data/lib/polyfill.rb +63 -0
- data/lib/polyfill/v2_4.rb +8 -0
- data/lib/polyfill/v2_4/array.rb +2 -2
- data/lib/polyfill/v2_4/array/instance.rb +11 -0
- data/lib/polyfill/v2_4/array/instance/concat.rb +32 -0
- data/lib/polyfill/v2_4/comparable.rb +2 -2
- data/lib/polyfill/v2_4/comparable/instance.rb +11 -0
- data/lib/polyfill/v2_4/comparable/instance/clamp.rb +37 -0
- data/lib/polyfill/v2_4/dir.rb +9 -0
- data/lib/polyfill/v2_4/dir/class.rb +11 -0
- data/lib/polyfill/v2_4/dir/class/empty_q.rb +25 -0
- data/lib/polyfill/v2_4/file.rb +9 -0
- data/lib/polyfill/v2_4/file/class.rb +11 -0
- data/lib/polyfill/v2_4/file/class/empty_q.rb +25 -0
- data/lib/polyfill/v2_4/float.rb +2 -6
- data/lib/polyfill/v2_4/float/instance.rb +15 -0
- data/lib/polyfill/v2_4/float/instance/ceil.rb +34 -0
- data/lib/polyfill/v2_4/float/instance/floor.rb +34 -0
- data/lib/polyfill/v2_4/float/instance/truncate.rb +34 -0
- data/lib/polyfill/v2_4/hash.rb +2 -8
- data/lib/polyfill/v2_4/hash/instance.rb +17 -0
- data/lib/polyfill/v2_4/hash/instance/compact.rb +25 -0
- data/lib/polyfill/v2_4/hash/instance/compact_e.rb +25 -0
- data/lib/polyfill/v2_4/hash/instance/transform_values.rb +35 -0
- data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +35 -0
- data/lib/polyfill/v2_4/integer.rb +2 -10
- data/lib/polyfill/v2_4/integer/instance.rb +19 -0
- data/lib/polyfill/v2_4/integer/instance/ceil.rb +30 -0
- data/lib/polyfill/v2_4/integer/instance/digits.rb +36 -0
- data/lib/polyfill/v2_4/integer/instance/floor.rb +30 -0
- data/lib/polyfill/v2_4/integer/instance/round.rb +33 -0
- data/lib/polyfill/v2_4/integer/instance/truncate.rb +30 -0
- data/lib/polyfill/v2_4/io.rb +11 -0
- data/lib/polyfill/v2_4/io/class.rb +13 -0
- data/lib/polyfill/v2_4/io/class/foreach.rb +67 -0
- data/lib/polyfill/v2_4/io/class/readlines.rb +38 -0
- data/lib/polyfill/v2_4/io/instance.rb +17 -0
- data/lib/polyfill/v2_4/io/instance/each_line.rb +67 -0
- data/lib/polyfill/v2_4/io/instance/gets.rb +38 -0
- data/lib/polyfill/v2_4/io/instance/readline.rb +38 -0
- data/lib/polyfill/v2_4/io/instance/readlines.rb +38 -0
- data/lib/polyfill/v2_4/match_data.rb +2 -4
- data/lib/polyfill/v2_4/match_data/instance.rb +13 -0
- data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +27 -0
- data/lib/polyfill/v2_4/match_data/instance/values_at.rb +27 -0
- data/lib/polyfill/v2_4/numeric.rb +2 -4
- data/lib/polyfill/v2_4/numeric/instance.rb +13 -0
- data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +25 -0
- data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +25 -0
- data/lib/polyfill/v2_4/string.rb +2 -4
- data/lib/polyfill/v2_4/string/instance.rb +13 -0
- data/lib/polyfill/v2_4/string/instance/concat.rb +32 -0
- data/lib/polyfill/v2_4/string/instance/prepend.rb +32 -0
- data/lib/polyfill/v2_4/string_io.rb +9 -0
- data/lib/polyfill/v2_4/string_io/instance.rb +17 -0
- data/lib/polyfill/v2_4/string_io/instance/each_line.rb +19 -0
- data/lib/polyfill/v2_4/string_io/instance/gets.rb +19 -0
- data/lib/polyfill/v2_4/string_io/instance/readline.rb +19 -0
- data/lib/polyfill/v2_4/string_io/instance/readlines.rb +19 -0
- data/lib/polyfill/version.rb +1 -1
- metadata +51 -22
- data/lib/polyfill/v2_4/array/concat.rb +0 -26
- data/lib/polyfill/v2_4/comparable/clamp.rb +0 -31
- data/lib/polyfill/v2_4/float/ceil.rb +0 -28
- data/lib/polyfill/v2_4/float/floor.rb +0 -28
- data/lib/polyfill/v2_4/float/truncate.rb +0 -28
- data/lib/polyfill/v2_4/hash/compact.rb +0 -19
- data/lib/polyfill/v2_4/hash/compact_e.rb +0 -19
- data/lib/polyfill/v2_4/hash/transform_values.rb +0 -29
- data/lib/polyfill/v2_4/hash/transform_values_e.rb +0 -29
- data/lib/polyfill/v2_4/integer/ceil.rb +0 -24
- data/lib/polyfill/v2_4/integer/digits.rb +0 -30
- data/lib/polyfill/v2_4/integer/floor.rb +0 -24
- data/lib/polyfill/v2_4/integer/round.rb +0 -27
- data/lib/polyfill/v2_4/integer/truncate.rb +0 -24
- data/lib/polyfill/v2_4/match_data/named_captures.rb +0 -21
- data/lib/polyfill/v2_4/match_data/values_at.rb +0 -21
- data/lib/polyfill/v2_4/numeric/finite_q.rb +0 -19
- data/lib/polyfill/v2_4/numeric/infinite_q.rb +0 -19
- data/lib/polyfill/v2_4/string/concat.rb +0 -26
- data/lib/polyfill/v2_4/string/prepend.rb +0 -26
@@ -0,0 +1,30 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Integer
|
4
|
+
module Instance
|
5
|
+
module Floor
|
6
|
+
module Method
|
7
|
+
def floor(ndigits = 0)
|
8
|
+
ndigits = ndigits.to_int
|
9
|
+
return super() if ndigits == 0
|
10
|
+
return to_f if ndigits > 0
|
11
|
+
|
12
|
+
place = 10 ** -ndigits
|
13
|
+
(self.to_f / place).floor * place
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if RUBY_VERSION < '2.4.0'
|
18
|
+
refine ::Integer do
|
19
|
+
include Method
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.include Method
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Integer
|
4
|
+
module Instance
|
5
|
+
module Round
|
6
|
+
module Method
|
7
|
+
def round(ndigits = 0, half: nil)
|
8
|
+
unless [nil, :down, :even, :up, 'down', 'even', 'up'].include?(half)
|
9
|
+
raise ArgumentError, "invalid rounding mode: #{half}"
|
10
|
+
end
|
11
|
+
ndigits = ndigits.to_int
|
12
|
+
return super() if ndigits == 0
|
13
|
+
return to_f if ndigits > 0
|
14
|
+
|
15
|
+
place = 10 ** -ndigits
|
16
|
+
(self.to_f / place).round * place
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if RUBY_VERSION < '2.4.0'
|
21
|
+
refine ::Integer do
|
22
|
+
include Method
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.include Method
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Integer
|
4
|
+
module Instance
|
5
|
+
module Truncate
|
6
|
+
module Method
|
7
|
+
def truncate(ndigits = 0)
|
8
|
+
ndigits = ndigits.to_int
|
9
|
+
return super() if ndigits == 0
|
10
|
+
return to_f if ndigits > 0
|
11
|
+
|
12
|
+
place = 10 ** -ndigits
|
13
|
+
(self.to_f / place).truncate * place
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if RUBY_VERSION < '2.4.0'
|
18
|
+
refine ::Integer do
|
19
|
+
include Method
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.include Method
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Class
|
5
|
+
module Foreach
|
6
|
+
module Method
|
7
|
+
def foreach(name, *args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
chomps = hash[0] && hash[0][:chomp]
|
11
|
+
|
12
|
+
unless block_given?
|
13
|
+
if chomps
|
14
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
15
|
+
|
16
|
+
return Enumerator.new do |yielder|
|
17
|
+
block =
|
18
|
+
if separator
|
19
|
+
Proc.new do |line|
|
20
|
+
yielder.yield(line.chomp(separator))
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Proc.new do |line|
|
24
|
+
yielder.yield(line.chomp)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
super(name, *others, &block)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
return super(name, *others)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
block =
|
35
|
+
if chomps
|
36
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
37
|
+
if separator
|
38
|
+
Proc.new do |line|
|
39
|
+
yield(line.chomp(separator))
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Proc.new do |line|
|
43
|
+
yield(line.chomp)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
Proc.new
|
48
|
+
end
|
49
|
+
|
50
|
+
super(name, *others, &block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if RUBY_VERSION < '2.4.0'
|
55
|
+
refine ::IO.singleton_class do
|
56
|
+
include Method
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.included(base)
|
60
|
+
base.include Method
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Class
|
5
|
+
module Readlines
|
6
|
+
module Method
|
7
|
+
def readlines(file_name, *args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
inputs = super(file_name, *others)
|
11
|
+
|
12
|
+
if hash[0] && hash[0][:chomp]
|
13
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
if separator
|
15
|
+
inputs.each { |input| input.chomp!(separator) }
|
16
|
+
else
|
17
|
+
inputs.each(&:chomp!)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
inputs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_VERSION < '2.4.0'
|
26
|
+
refine ::IO.singleton_class do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'polyfill/v2_4/io/instance/each_line'
|
2
|
+
require 'polyfill/v2_4/io/instance/gets'
|
3
|
+
require 'polyfill/v2_4/io/instance/readline'
|
4
|
+
require 'polyfill/v2_4/io/instance/readlines'
|
5
|
+
|
6
|
+
module Polyfill
|
7
|
+
module V2_4
|
8
|
+
module IO
|
9
|
+
module Instance
|
10
|
+
include EachLine
|
11
|
+
include Gets
|
12
|
+
include Readline
|
13
|
+
include Readlines
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Instance
|
5
|
+
module EachLine
|
6
|
+
module Method
|
7
|
+
def each_line(*args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
chomps = hash[0] && hash[0][:chomp]
|
11
|
+
|
12
|
+
unless block_given?
|
13
|
+
if chomps
|
14
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
15
|
+
|
16
|
+
return Enumerator.new do |yielder|
|
17
|
+
block =
|
18
|
+
if separator
|
19
|
+
Proc.new do |line|
|
20
|
+
yielder.yield(line.chomp(separator))
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Proc.new do |line|
|
24
|
+
yielder.yield(line.chomp)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
super(*others, &block)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
return super(*others)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
block =
|
35
|
+
if chomps
|
36
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
37
|
+
if separator
|
38
|
+
Proc.new do |line|
|
39
|
+
yield(line.chomp(separator))
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Proc.new do |line|
|
43
|
+
yield(line.chomp)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
Proc.new
|
48
|
+
end
|
49
|
+
|
50
|
+
super(*others, &block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if RUBY_VERSION < '2.4.0'
|
55
|
+
refine ::IO do
|
56
|
+
include Method
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.included(base)
|
60
|
+
base.include Method
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Instance
|
5
|
+
module Gets
|
6
|
+
module Method
|
7
|
+
def gets(*args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
input = super(*others)
|
11
|
+
|
12
|
+
if !input.nil? && hash[0] && hash[0][:chomp]
|
13
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
if separator
|
15
|
+
input.chomp!(separator)
|
16
|
+
else
|
17
|
+
input.chomp!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
input
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_VERSION < '2.4.0'
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Instance
|
5
|
+
module Readline
|
6
|
+
module Method
|
7
|
+
def readline(*args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
input = super(*others)
|
11
|
+
|
12
|
+
if hash[0] && hash[0][:chomp]
|
13
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
if separator
|
15
|
+
input.chomp!(separator)
|
16
|
+
else
|
17
|
+
input.chomp!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
input
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_VERSION < '2.4.0'
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module IO
|
4
|
+
module Instance
|
5
|
+
module Readlines
|
6
|
+
module Method
|
7
|
+
def readlines(*args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
|
10
|
+
inputs = super(*others)
|
11
|
+
|
12
|
+
if hash[0] && hash[0][:chomp]
|
13
|
+
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
if separator
|
15
|
+
inputs.each { |input| input.chomp!(separator) }
|
16
|
+
else
|
17
|
+
inputs.each(&:chomp!)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
inputs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_VERSION < '2.4.0'
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'polyfill/v2_4/match_data/
|
2
|
-
require 'polyfill/v2_4/match_data/values_at'
|
1
|
+
require 'polyfill/v2_4/match_data/instance'
|
3
2
|
|
4
3
|
module Polyfill
|
5
4
|
module V2_4
|
6
5
|
module MatchData
|
7
|
-
include
|
8
|
-
include ValuesAt
|
6
|
+
include Instance
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|