polyfill 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +3 -2
  4. data/CHANGELOG.md +26 -10
  5. data/CONTRIBUTING.md +0 -2
  6. data/README.md +107 -28
  7. data/lib/polyfill.rb +168 -74
  8. data/lib/polyfill/utils.rb +8 -3
  9. data/lib/polyfill/v2_2.rb +9 -0
  10. data/lib/polyfill/v2_2/enumerable.rb +34 -0
  11. data/lib/polyfill/v2_2/kernel.rb +9 -0
  12. data/lib/polyfill/v2_3.rb +2 -0
  13. data/lib/polyfill/v2_3/array.rb +22 -3
  14. data/lib/polyfill/v2_3/enumerable.rb +48 -3
  15. data/lib/polyfill/v2_3/enumerator/lazy.rb +7 -3
  16. data/lib/polyfill/v2_3/hash.rb +39 -3
  17. data/lib/polyfill/v2_3/kernel.rb +17 -0
  18. data/lib/polyfill/v2_3/string.rb +23 -5
  19. data/lib/polyfill/v2_3/struct.rb +22 -3
  20. data/lib/polyfill/v2_4/array.rb +25 -3
  21. data/lib/polyfill/v2_4/comparable.rb +9 -3
  22. data/lib/polyfill/v2_4/dir.rb +5 -3
  23. data/lib/polyfill/v2_4/enumerable.rb +28 -3
  24. data/lib/polyfill/v2_4/enumerator/lazy.rb +15 -3
  25. data/lib/polyfill/v2_4/file.rb +5 -3
  26. data/lib/polyfill/v2_4/float.rb +38 -3
  27. data/lib/polyfill/v2_4/hash.rb +35 -3
  28. data/lib/polyfill/v2_4/i_p_addr.rb +11 -3
  29. data/lib/polyfill/v2_4/integer.rb +53 -3
  30. data/lib/polyfill/v2_4/io.rb +166 -4
  31. data/lib/polyfill/v2_4/match_data.rb +11 -3
  32. data/lib/polyfill/v2_4/numeric.rb +15 -3
  33. data/lib/polyfill/v2_4/object.rb +9 -3
  34. data/lib/polyfill/v2_4/pathname.rb +7 -3
  35. data/lib/polyfill/v2_4/regexp.rb +3 -3
  36. data/lib/polyfill/v2_4/string.rb +110 -4
  37. data/lib/polyfill/v2_4/string_io.rb +166 -2
  38. data/lib/polyfill/v2_4/symbol.rb +17 -3
  39. data/lib/polyfill/version.rb +1 -1
  40. data/polyfill.gemspec +1 -1
  41. metadata +7 -98
  42. data/lib/polyfill/v2_3/array/instance.rb +0 -11
  43. data/lib/polyfill/v2_3/array/instance/dig.rb +0 -42
  44. data/lib/polyfill/v2_3/enumerable/instance.rb +0 -15
  45. data/lib/polyfill/v2_3/enumerable/instance/chunk_while.rb +0 -70
  46. data/lib/polyfill/v2_3/enumerable/instance/grep_v.rb +0 -48
  47. data/lib/polyfill/v2_3/enumerable/instance/slice_before.rb +0 -48
  48. data/lib/polyfill/v2_3/enumerator/lazy/instance.rb +0 -13
  49. data/lib/polyfill/v2_3/enumerator/lazy/instance/grep_v.rb +0 -31
  50. data/lib/polyfill/v2_3/hash/instance.rb +0 -15
  51. data/lib/polyfill/v2_3/hash/instance/dig.rb +0 -17
  52. data/lib/polyfill/v2_3/hash/instance/fetch_values.rb +0 -32
  53. data/lib/polyfill/v2_3/hash/instance/to_proc.rb +0 -23
  54. data/lib/polyfill/v2_3/string/class.rb +0 -11
  55. data/lib/polyfill/v2_3/string/class/new.rb +0 -33
  56. data/lib/polyfill/v2_3/string/instance.rb +0 -13
  57. data/lib/polyfill/v2_3/string/instance/minus_unary.rb +0 -23
  58. data/lib/polyfill/v2_3/string/instance/plus_unary.rb +0 -23
  59. data/lib/polyfill/v2_3/struct/instance.rb +0 -11
  60. data/lib/polyfill/v2_3/struct/instance/dig.rb +0 -17
  61. data/lib/polyfill/v2_4/array/instance.rb +0 -13
  62. data/lib/polyfill/v2_4/array/instance/concat.rb +0 -30
  63. data/lib/polyfill/v2_4/array/instance/sum.rb +0 -17
  64. data/lib/polyfill/v2_4/comparable/instance.rb +0 -11
  65. data/lib/polyfill/v2_4/comparable/instance/clamp.rb +0 -35
  66. data/lib/polyfill/v2_4/dir/class.rb +0 -11
  67. data/lib/polyfill/v2_4/dir/class/empty_q.rb +0 -23
  68. data/lib/polyfill/v2_4/enumerable/instance.rb +0 -15
  69. data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +0 -48
  70. data/lib/polyfill/v2_4/enumerable/instance/sum.rb +0 -52
  71. data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +0 -45
  72. data/lib/polyfill/v2_4/enumerator/lazy/instance.rb +0 -15
  73. data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +0 -29
  74. data/lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb +0 -33
  75. data/lib/polyfill/v2_4/file/class.rb +0 -11
  76. data/lib/polyfill/v2_4/file/class/empty_q.rb +0 -23
  77. data/lib/polyfill/v2_4/float/instance.rb +0 -15
  78. data/lib/polyfill/v2_4/float/instance/ceil.rb +0 -32
  79. data/lib/polyfill/v2_4/float/instance/floor.rb +0 -32
  80. data/lib/polyfill/v2_4/float/instance/truncate.rb +0 -32
  81. data/lib/polyfill/v2_4/hash/instance.rb +0 -17
  82. data/lib/polyfill/v2_4/hash/instance/compact.rb +0 -23
  83. data/lib/polyfill/v2_4/hash/instance/compact_e.rb +0 -23
  84. data/lib/polyfill/v2_4/hash/instance/transform_values.rb +0 -33
  85. data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +0 -33
  86. data/lib/polyfill/v2_4/i_p_addr/instance.rb +0 -13
  87. data/lib/polyfill/v2_4/i_p_addr/instance/equalequal.rb +0 -27
  88. data/lib/polyfill/v2_4/i_p_addr/instance/lessthanequalgreaterthan.rb +0 -27
  89. data/lib/polyfill/v2_4/integer/instance.rb +0 -19
  90. data/lib/polyfill/v2_4/integer/instance/ceil.rb +0 -28
  91. data/lib/polyfill/v2_4/integer/instance/digits.rb +0 -34
  92. data/lib/polyfill/v2_4/integer/instance/floor.rb +0 -28
  93. data/lib/polyfill/v2_4/integer/instance/round.rb +0 -31
  94. data/lib/polyfill/v2_4/integer/instance/truncate.rb +0 -28
  95. data/lib/polyfill/v2_4/io/class.rb +0 -13
  96. data/lib/polyfill/v2_4/io/class/foreach.rb +0 -55
  97. data/lib/polyfill/v2_4/io/class/readlines.rb +0 -37
  98. data/lib/polyfill/v2_4/io/instance.rb +0 -19
  99. data/lib/polyfill/v2_4/io/instance/each_line.rb +0 -54
  100. data/lib/polyfill/v2_4/io/instance/gets.rb +0 -37
  101. data/lib/polyfill/v2_4/io/instance/lines.rb +0 -54
  102. data/lib/polyfill/v2_4/io/instance/readline.rb +0 -37
  103. data/lib/polyfill/v2_4/io/instance/readlines.rb +0 -37
  104. data/lib/polyfill/v2_4/match_data/instance.rb +0 -13
  105. data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +0 -25
  106. data/lib/polyfill/v2_4/match_data/instance/values_at.rb +0 -25
  107. data/lib/polyfill/v2_4/numeric/instance.rb +0 -17
  108. data/lib/polyfill/v2_4/numeric/instance/clone.rb +0 -23
  109. data/lib/polyfill/v2_4/numeric/instance/dup.rb +0 -23
  110. data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +0 -23
  111. data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +0 -23
  112. data/lib/polyfill/v2_4/object/instance.rb +0 -11
  113. data/lib/polyfill/v2_4/object/instance/clone.rb +0 -29
  114. data/lib/polyfill/v2_4/pathname/instance.rb +0 -11
  115. data/lib/polyfill/v2_4/pathname/instance/empty_q.rb +0 -29
  116. data/lib/polyfill/v2_4/regexp/instance.rb +0 -11
  117. data/lib/polyfill/v2_4/regexp/instance/match_q.rb +0 -23
  118. data/lib/polyfill/v2_4/string/class.rb +0 -11
  119. data/lib/polyfill/v2_4/string/class/new.rb +0 -26
  120. data/lib/polyfill/v2_4/string/instance.rb +0 -23
  121. data/lib/polyfill/v2_4/string/instance/casecmp_q.rb +0 -23
  122. data/lib/polyfill/v2_4/string/instance/concat.rb +0 -30
  123. data/lib/polyfill/v2_4/string/instance/each_line.rb +0 -17
  124. data/lib/polyfill/v2_4/string/instance/lines.rb +0 -55
  125. data/lib/polyfill/v2_4/string/instance/match_q.rb +0 -23
  126. data/lib/polyfill/v2_4/string/instance/prepend.rb +0 -30
  127. data/lib/polyfill/v2_4/string/instance/unpack1.rb +0 -23
  128. data/lib/polyfill/v2_4/string_io/instance.rb +0 -17
  129. data/lib/polyfill/v2_4/string_io/instance/each_line.rb +0 -17
  130. data/lib/polyfill/v2_4/string_io/instance/gets.rb +0 -17
  131. data/lib/polyfill/v2_4/string_io/instance/readline.rb +0 -17
  132. data/lib/polyfill/v2_4/string_io/instance/readlines.rb +0 -17
  133. data/lib/polyfill/v2_4/symbol/instance.rb +0 -15
  134. data/lib/polyfill/v2_4/symbol/instance/casecmp_q.rb +0 -25
  135. data/lib/polyfill/v2_4/symbol/instance/match.rb +0 -27
  136. data/lib/polyfill/v2_4/symbol/instance/match_q.rb +0 -17
@@ -1,28 +0,0 @@
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
- (to_f / place).floor * place
14
- end
15
- end
16
-
17
- refine ::Integer do
18
- include Method
19
- end
20
-
21
- def self.included(base)
22
- base.include Method
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,31 +0,0 @@
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
- (to_f / place).round * place
17
- end
18
- end
19
-
20
- refine ::Integer do
21
- include Method
22
- end
23
-
24
- def self.included(base)
25
- base.include Method
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,28 +0,0 @@
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
- (to_f / place).truncate * place
14
- end
15
- end
16
-
17
- refine ::Integer do
18
- include Method
19
- end
20
-
21
- def self.included(base)
22
- base.include Method
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,13 +0,0 @@
1
- require_relative 'class/foreach'
2
- require_relative 'class/readlines'
3
-
4
- module Polyfill
5
- module V2_4
6
- module IO
7
- module Class
8
- include Foreach
9
- include Readlines
10
- end
11
- end
12
- end
13
- end
@@ -1,55 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Class
7
- module Foreach
8
- module Method
9
- def foreach(name, *args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
- chomps = hash[0] && hash[0][:chomp]
12
-
13
- unless block_given?
14
- return super(name, *others) unless chomps
15
-
16
- separator = others.find do |other|
17
- other.respond_to?(:to_str)
18
- end || $INPUT_RECORD_SEPARATOR
19
-
20
- return ::Enumerator.new do |yielder|
21
- super(name, *others) do |line|
22
- yielder.yield(line.chomp(separator))
23
- end
24
- end
25
- end
26
-
27
- block =
28
- if chomps
29
- separator = others.find do |other|
30
- other.respond_to?(:to_str)
31
- end || $INPUT_RECORD_SEPARATOR
32
-
33
- proc do |line|
34
- yield(line.chomp(separator))
35
- end
36
- else
37
- ::Proc.new
38
- end
39
-
40
- super(name, *others, &block)
41
- end
42
- end
43
-
44
- refine ::IO.singleton_class do
45
- include Method
46
- end
47
-
48
- def self.included(base)
49
- base.include Method
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,37 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Class
7
- module Readlines
8
- module Method
9
- def readlines(file_name, *args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
-
12
- inputs = super(file_name, *others)
13
-
14
- if hash[0] && hash[0][:chomp]
15
- separator = others.find do |other|
16
- other.respond_to?(:to_str)
17
- end || $INPUT_RECORD_SEPARATOR
18
-
19
- inputs.each { |input| input.chomp!(separator) }
20
- end
21
-
22
- inputs
23
- end
24
- end
25
-
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
@@ -1,19 +0,0 @@
1
- require_relative 'instance/each_line'
2
- require_relative 'instance/gets'
3
- require_relative 'instance/lines'
4
- require_relative 'instance/readline'
5
- require_relative 'instance/readlines'
6
-
7
- module Polyfill
8
- module V2_4
9
- module IO
10
- module Instance
11
- include EachLine
12
- include Gets
13
- include Lines
14
- include Readline
15
- include Readlines
16
- end
17
- end
18
- end
19
- end
@@ -1,54 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Instance
7
- module EachLine
8
- module Method
9
- def each_line(*args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
- chomps = hash[0] && hash[0][:chomp]
12
-
13
- unless block_given?
14
- return super(*others) unless chomps
15
-
16
- separator = others.find do |other|
17
- other.respond_to?(:to_str)
18
- end || $INPUT_RECORD_SEPARATOR
19
- return ::Enumerator.new do |yielder|
20
- super(*others) do |line|
21
- yielder.yield(line.chomp(separator))
22
- end
23
- end
24
- end
25
-
26
- block =
27
- if chomps
28
- separator = others.find do |other|
29
- other.respond_to?(:to_str)
30
- end || $INPUT_RECORD_SEPARATOR
31
-
32
- proc do |line|
33
- yield(line.chomp(separator))
34
- end
35
- else
36
- ::Proc.new
37
- end
38
-
39
- super(*others, &block)
40
- end
41
- end
42
-
43
- refine ::IO do
44
- include Method
45
- end
46
-
47
- def self.included(base)
48
- base.include Method
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,37 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Instance
7
- module Gets
8
- module Method
9
- def gets(*args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
-
12
- input = super(*others)
13
-
14
- if !input.nil? && hash[0] && hash[0][:chomp]
15
- separator = others.find do |other|
16
- other.respond_to?(:to_str)
17
- end || $INPUT_RECORD_SEPARATOR
18
-
19
- input.chomp!(separator)
20
- end
21
-
22
- input
23
- end
24
- end
25
-
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
@@ -1,54 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Instance
7
- module Lines
8
- module Method
9
- def lines(*args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
- chomps = hash[0] && hash[0][:chomp]
12
-
13
- unless block_given?
14
- return super(*others) unless chomps
15
-
16
- separator = others.find do |other|
17
- other.respond_to?(:to_str)
18
- end || $INPUT_RECORD_SEPARATOR
19
- return ::Enumerator.new do |yielder|
20
- super(*others) do |line|
21
- yielder.yield(line.chomp(separator))
22
- end
23
- end
24
- end
25
-
26
- block =
27
- if chomps
28
- separator = others.find do |other|
29
- other.respond_to?(:to_str)
30
- end || $INPUT_RECORD_SEPARATOR
31
-
32
- proc do |line|
33
- yield(line.chomp(separator))
34
- end
35
- else
36
- ::Proc.new
37
- end
38
-
39
- super(*others, &block)
40
- end
41
- end
42
-
43
- refine ::IO do
44
- include Method
45
- end
46
-
47
- def self.included(base)
48
- base.include Method
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,37 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Instance
7
- module Readline
8
- module Method
9
- def readline(*args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
-
12
- input = super(*others)
13
-
14
- if hash[0] && hash[0][:chomp]
15
- separator = others.find do |other|
16
- other.respond_to?(:to_str)
17
- end || $INPUT_RECORD_SEPARATOR
18
-
19
- input.chomp!(separator)
20
- end
21
-
22
- input
23
- end
24
- end
25
-
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
@@ -1,37 +0,0 @@
1
- require 'English'
2
-
3
- module Polyfill
4
- module V2_4
5
- module IO
6
- module Instance
7
- module Readlines
8
- module Method
9
- def readlines(*args)
10
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
11
-
12
- inputs = super(*others)
13
-
14
- if hash[0] && hash[0][:chomp]
15
- separator = others.find do |other|
16
- other.respond_to?(:to_str)
17
- end || $INPUT_RECORD_SEPARATOR
18
-
19
- inputs.each { |input| input.chomp!(separator) }
20
- end
21
-
22
- inputs
23
- end
24
- end
25
-
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