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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -1
  3. data/README.md +30 -44
  4. data/lib/polyfill.rb +63 -0
  5. data/lib/polyfill/v2_4.rb +8 -0
  6. data/lib/polyfill/v2_4/array.rb +2 -2
  7. data/lib/polyfill/v2_4/array/instance.rb +11 -0
  8. data/lib/polyfill/v2_4/array/instance/concat.rb +32 -0
  9. data/lib/polyfill/v2_4/comparable.rb +2 -2
  10. data/lib/polyfill/v2_4/comparable/instance.rb +11 -0
  11. data/lib/polyfill/v2_4/comparable/instance/clamp.rb +37 -0
  12. data/lib/polyfill/v2_4/dir.rb +9 -0
  13. data/lib/polyfill/v2_4/dir/class.rb +11 -0
  14. data/lib/polyfill/v2_4/dir/class/empty_q.rb +25 -0
  15. data/lib/polyfill/v2_4/file.rb +9 -0
  16. data/lib/polyfill/v2_4/file/class.rb +11 -0
  17. data/lib/polyfill/v2_4/file/class/empty_q.rb +25 -0
  18. data/lib/polyfill/v2_4/float.rb +2 -6
  19. data/lib/polyfill/v2_4/float/instance.rb +15 -0
  20. data/lib/polyfill/v2_4/float/instance/ceil.rb +34 -0
  21. data/lib/polyfill/v2_4/float/instance/floor.rb +34 -0
  22. data/lib/polyfill/v2_4/float/instance/truncate.rb +34 -0
  23. data/lib/polyfill/v2_4/hash.rb +2 -8
  24. data/lib/polyfill/v2_4/hash/instance.rb +17 -0
  25. data/lib/polyfill/v2_4/hash/instance/compact.rb +25 -0
  26. data/lib/polyfill/v2_4/hash/instance/compact_e.rb +25 -0
  27. data/lib/polyfill/v2_4/hash/instance/transform_values.rb +35 -0
  28. data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +35 -0
  29. data/lib/polyfill/v2_4/integer.rb +2 -10
  30. data/lib/polyfill/v2_4/integer/instance.rb +19 -0
  31. data/lib/polyfill/v2_4/integer/instance/ceil.rb +30 -0
  32. data/lib/polyfill/v2_4/integer/instance/digits.rb +36 -0
  33. data/lib/polyfill/v2_4/integer/instance/floor.rb +30 -0
  34. data/lib/polyfill/v2_4/integer/instance/round.rb +33 -0
  35. data/lib/polyfill/v2_4/integer/instance/truncate.rb +30 -0
  36. data/lib/polyfill/v2_4/io.rb +11 -0
  37. data/lib/polyfill/v2_4/io/class.rb +13 -0
  38. data/lib/polyfill/v2_4/io/class/foreach.rb +67 -0
  39. data/lib/polyfill/v2_4/io/class/readlines.rb +38 -0
  40. data/lib/polyfill/v2_4/io/instance.rb +17 -0
  41. data/lib/polyfill/v2_4/io/instance/each_line.rb +67 -0
  42. data/lib/polyfill/v2_4/io/instance/gets.rb +38 -0
  43. data/lib/polyfill/v2_4/io/instance/readline.rb +38 -0
  44. data/lib/polyfill/v2_4/io/instance/readlines.rb +38 -0
  45. data/lib/polyfill/v2_4/match_data.rb +2 -4
  46. data/lib/polyfill/v2_4/match_data/instance.rb +13 -0
  47. data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +27 -0
  48. data/lib/polyfill/v2_4/match_data/instance/values_at.rb +27 -0
  49. data/lib/polyfill/v2_4/numeric.rb +2 -4
  50. data/lib/polyfill/v2_4/numeric/instance.rb +13 -0
  51. data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +25 -0
  52. data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +25 -0
  53. data/lib/polyfill/v2_4/string.rb +2 -4
  54. data/lib/polyfill/v2_4/string/instance.rb +13 -0
  55. data/lib/polyfill/v2_4/string/instance/concat.rb +32 -0
  56. data/lib/polyfill/v2_4/string/instance/prepend.rb +32 -0
  57. data/lib/polyfill/v2_4/string_io.rb +9 -0
  58. data/lib/polyfill/v2_4/string_io/instance.rb +17 -0
  59. data/lib/polyfill/v2_4/string_io/instance/each_line.rb +19 -0
  60. data/lib/polyfill/v2_4/string_io/instance/gets.rb +19 -0
  61. data/lib/polyfill/v2_4/string_io/instance/readline.rb +19 -0
  62. data/lib/polyfill/v2_4/string_io/instance/readlines.rb +19 -0
  63. data/lib/polyfill/version.rb +1 -1
  64. metadata +51 -22
  65. data/lib/polyfill/v2_4/array/concat.rb +0 -26
  66. data/lib/polyfill/v2_4/comparable/clamp.rb +0 -31
  67. data/lib/polyfill/v2_4/float/ceil.rb +0 -28
  68. data/lib/polyfill/v2_4/float/floor.rb +0 -28
  69. data/lib/polyfill/v2_4/float/truncate.rb +0 -28
  70. data/lib/polyfill/v2_4/hash/compact.rb +0 -19
  71. data/lib/polyfill/v2_4/hash/compact_e.rb +0 -19
  72. data/lib/polyfill/v2_4/hash/transform_values.rb +0 -29
  73. data/lib/polyfill/v2_4/hash/transform_values_e.rb +0 -29
  74. data/lib/polyfill/v2_4/integer/ceil.rb +0 -24
  75. data/lib/polyfill/v2_4/integer/digits.rb +0 -30
  76. data/lib/polyfill/v2_4/integer/floor.rb +0 -24
  77. data/lib/polyfill/v2_4/integer/round.rb +0 -27
  78. data/lib/polyfill/v2_4/integer/truncate.rb +0 -24
  79. data/lib/polyfill/v2_4/match_data/named_captures.rb +0 -21
  80. data/lib/polyfill/v2_4/match_data/values_at.rb +0 -21
  81. data/lib/polyfill/v2_4/numeric/finite_q.rb +0 -19
  82. data/lib/polyfill/v2_4/numeric/infinite_q.rb +0 -19
  83. data/lib/polyfill/v2_4/string/concat.rb +0 -26
  84. data/lib/polyfill/v2_4/string/prepend.rb +0 -26
@@ -0,0 +1,11 @@
1
+ require 'polyfill/v2_4/file/class/empty_q'
2
+
3
+ module Polyfill
4
+ module V2_4
5
+ module File
6
+ module Class
7
+ include EmptyQ
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module File
4
+ module Class
5
+ module EmptyQ
6
+ module Method
7
+ def empty?(file_name)
8
+ zero?(file_name)
9
+ end
10
+ end
11
+
12
+ if RUBY_VERSION < '2.4.0'
13
+ refine ::File.singleton_class do
14
+ include Method
15
+ end
16
+
17
+ def self.included(base)
18
+ base.include Method
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,13 +1,9 @@
1
- require 'polyfill/v2_4/float/ceil'
2
- require 'polyfill/v2_4/float/floor'
3
- require 'polyfill/v2_4/float/truncate'
1
+ require 'polyfill/v2_4/float/instance'
4
2
 
5
3
  module Polyfill
6
4
  module V2_4
7
5
  module Float
8
- include Ceil
9
- include Floor
10
- include Truncate
6
+ include Instance
11
7
  end
12
8
  end
13
9
  end
@@ -0,0 +1,15 @@
1
+ require 'polyfill/v2_4/float/instance/ceil'
2
+ require 'polyfill/v2_4/float/instance/floor'
3
+ require 'polyfill/v2_4/float/instance/truncate'
4
+
5
+ module Polyfill
6
+ module V2_4
7
+ module Float
8
+ module Instance
9
+ include Ceil
10
+ include Floor
11
+ include Truncate
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
4
+ module Instance
5
+ module Ceil
6
+ module Method
7
+ def ceil(ndigits = 0)
8
+ ndigits = ndigits.to_int
9
+ return super() if ndigits == 0
10
+
11
+ if ndigits > 0
12
+ place = 10 ** ndigits
13
+ (self * place).ceil / place.to_f
14
+ else
15
+ place = 10 ** -ndigits
16
+ (self.to_f / place).ceil * place
17
+ end
18
+ end
19
+ end
20
+
21
+ if RUBY_VERSION < '2.4.0'
22
+ refine ::Float 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
34
+ end
@@ -0,0 +1,34 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
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
+
11
+ if ndigits > 0
12
+ place = 10 ** ndigits
13
+ (self * place).floor / place.to_f
14
+ else
15
+ place = 10 ** -ndigits
16
+ (self / place).floor * place
17
+ end
18
+ end
19
+ end
20
+
21
+ if RUBY_VERSION < '2.4.0'
22
+ refine ::Float 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
34
+ end
@@ -0,0 +1,34 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Float
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
+
11
+ if ndigits > 0
12
+ place = 10 ** ndigits
13
+ (self * place).truncate / place.to_f
14
+ else
15
+ place = 10 ** -ndigits
16
+ (self.to_f / place).truncate * place
17
+ end
18
+ end
19
+ end
20
+
21
+ if RUBY_VERSION < '2.4.0'
22
+ refine ::Float 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
34
+ end
@@ -1,15 +1,9 @@
1
- require 'polyfill/v2_4/hash/compact'
2
- require 'polyfill/v2_4/hash/compact_e'
3
- require 'polyfill/v2_4/hash/transform_values'
4
- require 'polyfill/v2_4/hash/transform_values_e'
1
+ require 'polyfill/v2_4/hash/instance'
5
2
 
6
3
  module Polyfill
7
4
  module V2_4
8
5
  module Hash
9
- include Compact
10
- include CompactE
11
- include TransformValues
12
- include TransformValuesE
6
+ include Instance
13
7
  end
14
8
  end
15
9
  end
@@ -0,0 +1,17 @@
1
+ require 'polyfill/v2_4/hash/instance/compact'
2
+ require 'polyfill/v2_4/hash/instance/compact_e'
3
+ require 'polyfill/v2_4/hash/instance/transform_values'
4
+ require 'polyfill/v2_4/hash/instance/transform_values_e'
5
+
6
+ module Polyfill
7
+ module V2_4
8
+ module Hash
9
+ module Instance
10
+ include Compact
11
+ include CompactE
12
+ include TransformValues
13
+ include TransformValuesE
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module Instance
5
+ module Compact
6
+ module Method
7
+ def compact
8
+ reject { |_, v| v.nil? }
9
+ end
10
+ end
11
+
12
+ if RUBY_VERSION < '2.4.0'
13
+ refine ::Hash do
14
+ include Method
15
+ end
16
+
17
+ def self.included(base)
18
+ base.include Method
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module Instance
5
+ module CompactE
6
+ module Method
7
+ def compact!
8
+ reject! { |_, v| v.nil? }
9
+ end
10
+ end
11
+
12
+ if RUBY_VERSION < '2.4.0'
13
+ refine ::Hash do
14
+ include Method
15
+ end
16
+
17
+ def self.included(base)
18
+ base.include Method
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module Instance
5
+ module TransformValues
6
+ module Method
7
+ def transform_values
8
+ unless block_given?
9
+ return Enumerator.new(keys.size) do |yielder|
10
+ each_with_object({}) do |(k, v), acc|
11
+ acc[k] = yielder.yield(v)
12
+ end
13
+ end
14
+ end
15
+
16
+ each_with_object({}) do |(k, v), acc|
17
+ acc[k] = yield(v)
18
+ end
19
+ end
20
+ end
21
+
22
+ if RUBY_VERSION < '2.4.0'
23
+ refine ::Hash do
24
+ include Method
25
+ end
26
+
27
+ def self.included(base)
28
+ base.include Method
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Hash
4
+ module Instance
5
+ module TransformValuesE
6
+ module Method
7
+ def transform_values!
8
+ unless block_given?
9
+ return Enumerator.new(keys.size) do |yielder|
10
+ replace(each_with_object({}) do |(k, v), acc|
11
+ acc[k] = yielder.yield(v)
12
+ end)
13
+ end
14
+ end
15
+
16
+ replace(each_with_object({}) do |(k, v), acc|
17
+ acc[k] = yield(v)
18
+ end)
19
+ end
20
+ end
21
+
22
+ if RUBY_VERSION < '2.4.0'
23
+ refine ::Hash do
24
+ include Method
25
+ end
26
+
27
+ def self.included(base)
28
+ base.include Method
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,17 +1,9 @@
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'
1
+ require 'polyfill/v2_4/integer/instance'
6
2
 
7
3
  module Polyfill
8
4
  module V2_4
9
5
  module Integer
10
- include Ceil
11
- include Digits
12
- include Floor
13
- include Round
14
- include Truncate
6
+ include Instance
15
7
  end
16
8
  end
17
9
  end
@@ -0,0 +1,19 @@
1
+ require 'polyfill/v2_4/integer/instance/ceil'
2
+ require 'polyfill/v2_4/integer/instance/digits'
3
+ require 'polyfill/v2_4/integer/instance/floor'
4
+ require 'polyfill/v2_4/integer/instance/round'
5
+ require 'polyfill/v2_4/integer/instance/truncate'
6
+
7
+ module Polyfill
8
+ module V2_4
9
+ module Integer
10
+ module Instance
11
+ include Ceil
12
+ include Digits
13
+ include Floor
14
+ include Round
15
+ include Truncate
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Instance
5
+ module Ceil
6
+ module Method
7
+ def ceil(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).ceil * 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,36 @@
1
+ module Polyfill
2
+ module V2_4
3
+ module Integer
4
+ module Instance
5
+ module Digits
6
+ module Method
7
+ def digits(base = 10)
8
+ base = base.to_int
9
+ raise Math::DomainError, 'out of domain' if self < 0
10
+ raise ArgumentError, 'negative radix' if base < 0
11
+ raise ArgumentError, "invalid radix #{base}" if base < 2
12
+
13
+ acc = []
14
+ remainder = self
15
+ while remainder > 0
16
+ remainder, value = remainder.divmod(base)
17
+ acc.push(value)
18
+ end
19
+ acc
20
+ end
21
+ end
22
+
23
+ if RUBY_VERSION < '2.4.0'
24
+ refine ::Integer do
25
+ include Method
26
+ end
27
+
28
+ def self.included(base)
29
+ base.include Method
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end