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,11 +0,0 @@
1
- require_relative 'instance/dig'
2
-
3
- module Polyfill
4
- module V2_3
5
- module Array
6
- module Instance
7
- include Dig
8
- end
9
- end
10
- end
11
- end
@@ -1,42 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Array
4
- module Instance
5
- module Dig
6
- module Method
7
- def dig(head, *rest)
8
- [head, *rest].reduce(self) do |value, accessor|
9
- next_value =
10
- case value
11
- when ::Array
12
- value.at(accessor)
13
- when ::Hash
14
- value[accessor]
15
- when ::Struct
16
- value[accessor] if value.members.include?(accessor)
17
- else
18
- begin
19
- break value.dig(*rest)
20
- rescue NoMethodError
21
- raise TypeError, "#{value.class} does not have a #dig method"
22
- end
23
- end
24
-
25
- break nil if next_value.nil?
26
- next_value
27
- end
28
- end
29
- end
30
-
31
- refine ::Array do
32
- include Method
33
- end
34
-
35
- def self.included(base)
36
- base.include Method
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,15 +0,0 @@
1
- require_relative 'instance/chunk_while'
2
- require_relative 'instance/grep_v'
3
- require_relative 'instance/slice_before'
4
-
5
- module Polyfill
6
- module V2_3
7
- module Enumerable
8
- module Instance
9
- include ChunkWhile
10
- include GrepV
11
- include SliceBefore
12
- end
13
- end
14
- end
15
- end
@@ -1,70 +0,0 @@
1
- require 'stringio'
2
-
3
- module Polyfill
4
- module V2_3
5
- module Enumerable
6
- module Instance
7
- module ChunkWhile
8
- module Method
9
- def chunk_while
10
- block = ::Proc.new
11
-
12
- return [self] if size == 1
13
-
14
- ::Enumerator.new do |yielder|
15
- output = []
16
- each_cons(2).with_index(1) do |(a, b), run|
17
- if run == size - 1
18
- if block.call(a, b)
19
- output.push(a, b)
20
- yielder << output
21
- else
22
- output.push(a)
23
- yielder << output
24
- yielder << [b]
25
- end
26
- else
27
- output.push(a)
28
- unless block.call(a, b)
29
- yielder << output
30
- output = []
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- refine ::Array do
39
- include Method
40
- end
41
- refine ::Dir do
42
- include Method
43
- end
44
- refine ::Enumerator do
45
- include Method
46
- end
47
- refine ::Hash do
48
- include Method
49
- end
50
- refine ::IO do
51
- include Method
52
- end
53
- refine ::Range do
54
- include Method
55
- end
56
- refine ::StringIO do
57
- include Method
58
- end
59
- refine ::Struct do
60
- include Method
61
- end
62
-
63
- def self.included(base)
64
- base.include Method
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,48 +0,0 @@
1
- require 'stringio'
2
-
3
- module Polyfill
4
- module V2_3
5
- module Enumerable
6
- module Instance
7
- module GrepV
8
- module Method
9
- def grep_v(pattern)
10
- output = to_a - grep(pattern)
11
- output.map!(&::Proc.new) if block_given?
12
- output
13
- end
14
- end
15
-
16
- refine ::Array do
17
- include Method
18
- end
19
- refine ::Dir do
20
- include Method
21
- end
22
- refine ::Enumerator do
23
- include Method
24
- end
25
- refine ::Hash do
26
- include Method
27
- end
28
- refine ::IO do
29
- include Method
30
- end
31
- refine ::Range do
32
- include Method
33
- end
34
- refine ::StringIO do
35
- include Method
36
- end
37
- refine ::Struct do
38
- include Method
39
- end
40
-
41
- def self.included(base)
42
- base.include Method
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Enumerable
4
- module Instance
5
- module SliceBefore
6
- module Method
7
- def slice_before(*args)
8
- if !args.empty? && block_given?
9
- raise ArgumentError, 'wrong number of arguments (given 1, expected 0)'
10
- end
11
-
12
- super
13
- end
14
- end
15
-
16
- refine ::Array do
17
- include Method
18
- end
19
- refine ::Dir do
20
- include Method
21
- end
22
- refine ::Enumerator do
23
- include Method
24
- end
25
- refine ::Hash do
26
- include Method
27
- end
28
- refine ::IO do
29
- include Method
30
- end
31
- refine ::Range do
32
- include Method
33
- end
34
- refine ::StringIO do
35
- include Method
36
- end
37
- refine ::Struct do
38
- include Method
39
- end
40
-
41
- def self.included(base)
42
- base.include Method
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,13 +0,0 @@
1
- require_relative 'instance/grep_v'
2
-
3
- module Polyfill
4
- module V2_3
5
- module Enumerator
6
- module Lazy
7
- module Instance
8
- include GrepV
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Enumerator
4
- module Lazy
5
- module Instance
6
- module GrepV
7
- module Method
8
- using V2_3::Enumerable::Instance::GrepV
9
-
10
- def grep_v(pattern)
11
- ::Enumerator::Lazy.new(self) do |yielder, element|
12
- next if pattern === element # rubocop:disable Style/CaseEquality
13
-
14
- yielder << (block_given? ? yield(element) : element)
15
- end
16
- end
17
- end
18
-
19
- refine ::Enumerator::Lazy do
20
- include Method
21
- end
22
-
23
- def self.included(base)
24
- base.include Method
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- require_relative 'instance/dig'
2
- require_relative 'instance/fetch_values'
3
- require_relative 'instance/to_proc'
4
-
5
- module Polyfill
6
- module V2_3
7
- module Hash
8
- module Instance
9
- include Dig
10
- include FetchValues
11
- include ToProc
12
- end
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Hash
4
- module Instance
5
- module Dig
6
- refine ::Hash do
7
- include Array::Instance::Dig::Method
8
- end
9
-
10
- def self.included(base)
11
- base.include Array::Instance::Dig::Method
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,32 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Hash
4
- module Instance
5
- module FetchValues
6
- module Method
7
- def fetch_values(*keys)
8
- keys.each_with_object([]) do |key, values|
9
- value =
10
- if block_given?
11
- fetch(key, &::Proc.new)
12
- else
13
- fetch(key)
14
- end
15
-
16
- values << value
17
- end
18
- end
19
- end
20
-
21
- refine ::Hash 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
@@ -1,23 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module Hash
4
- module Instance
5
- module ToProc
6
- module Method
7
- def to_proc
8
- method(:[]).to_proc
9
- end
10
- end
11
-
12
- refine ::Hash do
13
- include Method
14
- end
15
-
16
- def self.included(base)
17
- base.include Method
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,11 +0,0 @@
1
- require_relative 'class/new'
2
-
3
- module Polyfill
4
- module V2_3
5
- module String
6
- module Class
7
- include New
8
- end
9
- end
10
- end
11
- end
@@ -1,33 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module String
4
- module Class
5
- module New
6
- module Method
7
- def new(*args)
8
- hash, others = args.partition { |arg| arg.is_a?(::Hash) }
9
- hash = hash.first
10
- encoding = hash && hash.delete(:encoding)
11
-
12
- if hash && !hash.keys.empty?
13
- raise ArgumentError, "unknown keyword: #{hash.keys.first}"
14
- end
15
-
16
- str = super(*others)
17
- str.encode!(encoding) if encoding
18
- str
19
- end
20
- end
21
-
22
- refine ::String.singleton_class do
23
- include Method
24
- end
25
-
26
- def self.included(base)
27
- base.include Method
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,13 +0,0 @@
1
- require_relative 'instance/plus_unary'
2
- require_relative 'instance/minus_unary'
3
-
4
- module Polyfill
5
- module V2_3
6
- module String
7
- module Instance
8
- include PlusUnary
9
- include MinusUnary
10
- end
11
- end
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- module Polyfill
2
- module V2_3
3
- module String
4
- module Instance
5
- module MinusUnary
6
- module Method
7
- def -@
8
- frozen? ? self : dup.freeze
9
- end
10
- end
11
-
12
- refine ::String do
13
- include Method
14
- end
15
-
16
- def self.included(base)
17
- base.include Method
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end