polyfill 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcf78a0e3232a09956c63e330dceee6477e1ca817175ca288f3c728564918a8b
4
- data.tar.gz: 9d70ef2d07ba52b3105d8dd0a900a257f7a5c71b0a49e56b783e67d16441fba6
3
+ metadata.gz: e4a9568a9912f29fcfe5b3d7a9df9710ac88a860f964cff51134563cb5d436b5
4
+ data.tar.gz: c448ec3ff53bcb22390a631a72a06c6a6f33463c4b17b394e27c4315c093fb5f
5
5
  SHA512:
6
- metadata.gz: d7ddd097309f6a251144437baf7994baf8f15d85634137eb1cf880d4a119b57ab8c532a7bfad61523cb3e58c2f9802c5b06857985c7574dfa55b55ef4382be50
7
- data.tar.gz: 5be3401b05404a346b7867ece1ef315a1acbddaa343df576803d3c8f84cf46dd2a746cefe957207ab70a89a997ef8fdfc12360329644a93f67ca7fa5310db7d7
6
+ metadata.gz: '03719c7924952b097c8b104a550701edb7afc5ee3335944b738eec527e11f0e7bf66f1bf10851c62a072675dc9fe05d3dc30faef085db6d79be4feee0a7bb4c0'
7
+ data.tar.gz: b6b01572c50499d6865fd55ecc516814a6fa03a5ce8853281d4ea4263465535860d2a33e1c7bf22bc8840b151e7786ec9e6c50dba7601eedabfe102e8b546911
@@ -1,5 +1,19 @@
1
1
  # Master
2
2
 
3
+ # [1.3.0][] (TBD)
4
+
5
+ ## Added
6
+
7
+ - v2.5 Enumerable#all?
8
+ - v2.5 Enumerable#any?
9
+ - v2.5 Enumerable#none?
10
+ - v2.5 Enumerable#one?
11
+ - v2.3 Array#bsearch_index
12
+ - v2.3 Hash#<
13
+ - v2.3 Hash#<=
14
+ - v2.3 Hash#>
15
+ - v2.3 Hash#>=
16
+
3
17
  # [1.2.0][] (2018-03-05)
4
18
 
5
19
  ## Added
data/README.md CHANGED
@@ -27,7 +27,7 @@ monkey patching** that may cause issues outside of your use.
27
27
  Add it to your Gemfile:
28
28
 
29
29
  ```ruby
30
- gem 'polyfill', '~> 1.2'
30
+ gem 'polyfill', '~> 1.3'
31
31
  ```
32
32
 
33
33
  Or install it manually:
@@ -141,15 +141,15 @@ though they have techically changed. `FrozenError` is a subclass of
141
141
  | ✓ | Dir | .children | New
142
142
  | ✓ | | .each_child | New
143
143
  | ✗ | | #glob | Accepts a new optional keyword argument, `:base`.
144
- | | Enumerable | #any? | Accepts a pattern argument.
145
- | | | #all? | Accepts a pattern argument.
146
- | | | #none? | Accepts a pattern argument.
147
- | | | #one? | Accepts a pattern argument.
144
+ | | Enumerable | #all? | Accepts a pattern argument.
145
+ | | | #any? | Accepts a pattern argument.
146
+ | | | #none? | Accepts a pattern argument.
147
+ | | | #one? | Accepts a pattern argument.
148
148
  | ✗ | ERB | .result_with_hash | New
149
149
  | ✗ | Exception | #full_message | New
150
150
  | ✗ | File | .identical? | Support ReFS 128bit ino on Windows 8.1 and later.
151
151
  | ✗ | | .lutime | New
152
- | ✗ | | .open | Accepts a new optional keyword argument, `:newline`.
152
+ | ✗ | | .open | Use of the optional argument `newline` now implies text mode.
153
153
  | ✗ | | #path | Raises an `IOError` for files opened with `File::Constants::TMPFILE` option.
154
154
  | ✗ | File::Stat | #atime | Support fractional second timestamps on Windows 8 and later.
155
155
  | ✗ | | #ctime | Support fractional second timestamps on Windows 8 and later.
@@ -349,7 +349,7 @@ though they have techically changed. `FrozenError` is a subclass of
349
349
  | | Object | Method | Changes |
350
350
  |:-:| ----------------------- | ------------------------ | ------- |
351
351
  | ✗ | ARGF | #read_nonblock | Accepts a new optional keyword argument, `exception`.
352
- | | Array | #bsearch_index | New
352
+ | | Array | #bsearch_index | New
353
353
  | ✓ | | #dig | New
354
354
  | ✗ | | #flatten | No longer calls `to_ary` on elements beyond the given level.
355
355
  | ✗ | | #flatten! | No longer calls `to_ary` on elements beyond the given level.
@@ -370,10 +370,10 @@ though they have techically changed. `FrozenError` is a subclass of
370
370
  | ✓ | Enumerator::Lazy | #grep_v | New
371
371
  | ✗ | File | .mkfifo | New
372
372
  | ✗ | File::Stat | #ino | On Windows, it always returned `0`, but now returns `BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low`.
373
- | | Hash | #< | New
374
- | | | #<= | New
375
- | | | #> | New
376
- | | | #>= | New
373
+ | | Hash | #< | New
374
+ | | | #<= | New
375
+ | | | #> | New
376
+ | | | #>= | New
377
377
  | ✓ | | #dig | New
378
378
  | ✓ | | #fetch_values | New
379
379
  | ✗ | | #inspect | No longer raises an error if its content returns a string which is not compatible with `Encoding.default_external`.
@@ -1,5 +1,5 @@
1
1
  module Polyfill
2
- module InternalUtils
2
+ module InternalUtils # rubocop:disable Metrics/ModuleLength
3
3
  VERSIONS = {
4
4
  '2.2' => 'V2_2',
5
5
  '2.3' => 'V2_3',
@@ -92,8 +92,12 @@ module Polyfill
92
92
  module_function :create_module
93
93
 
94
94
  def to_str(obj)
95
- unless obj.respond_to?(:to_str)
96
- raise TypeError, "no implicit conversion of #{obj.class} into String"
95
+ begin
96
+ unless obj.respond_to?(:to_str)
97
+ raise TypeError, "no implicit conversion of #{obj.class} into String"
98
+ end
99
+ rescue NoMethodError
100
+ raise TypeError, 'no implicit conversion of BasicObject into String'
97
101
  end
98
102
 
99
103
  obj.to_str
@@ -101,8 +105,12 @@ module Polyfill
101
105
  module_function :to_str
102
106
 
103
107
  def to_int(obj)
104
- unless obj.respond_to?(:to_int)
105
- raise TypeError, "no implicit conversion of #{obj.class} into Integer"
108
+ begin
109
+ unless obj.respond_to?(:to_int)
110
+ raise TypeError, "no implicit conversion of #{obj.class} into Integer"
111
+ end
112
+ rescue NoMethodError
113
+ raise TypeError, 'no implicit conversion of BasicObject into Integer'
106
114
  end
107
115
 
108
116
  obj.to_int
@@ -110,12 +118,29 @@ module Polyfill
110
118
  module_function :to_int
111
119
 
112
120
  def to_f(obj)
113
- unless obj.respond_to?(:to_f)
114
- raise TypeError, "no implicit conversion of #{obj.class} into Float"
121
+ begin
122
+ unless obj.respond_to?(:to_f)
123
+ raise TypeError, "no implicit conversion of #{obj.class} into Float"
124
+ end
125
+ rescue NoMethodError
126
+ raise TypeError, 'no implicit conversion of BasicObject into Float'
115
127
  end
116
128
 
117
129
  obj.to_f
118
130
  end
119
131
  module_function :to_f
132
+
133
+ def to_hash(obj)
134
+ begin
135
+ unless obj.respond_to?(:to_hash)
136
+ raise TypeError, "no implicit conversion of #{obj.class} into Hash"
137
+ end
138
+ rescue NoMethodError
139
+ raise TypeError, 'no implicit conversion of BasicObject into Hash'
140
+ end
141
+
142
+ obj.to_hash
143
+ end
144
+ module_function :to_hash
120
145
  end
121
146
  end
@@ -1,6 +1,16 @@
1
1
  module Polyfill
2
2
  module V2_3
3
3
  module Array
4
+ def bsearch_index
5
+ unless block_given?
6
+ return ::Enumerator.new do |yielder|
7
+ find_index(bsearch { |elem| yielder.yield(elem) })
8
+ end
9
+ end
10
+
11
+ find_index(bsearch(&::Proc.new))
12
+ end
13
+
4
14
  def dig(head, *rest)
5
15
  [head, *rest].reduce(self) do |value, accessor|
6
16
  next_value =
@@ -1,6 +1,34 @@
1
1
  module Polyfill
2
2
  module V2_3
3
3
  module Hash
4
+ def <(other)
5
+ other = InternalUtils.to_hash(other)
6
+
7
+ return false if size == other.size
8
+
9
+ all? { |k, v| other[k] == v }
10
+ end
11
+
12
+ def <=(other)
13
+ other = InternalUtils.to_hash(other)
14
+
15
+ all? { |k, v| other[k] == v }
16
+ end
17
+
18
+ def >(other)
19
+ other = InternalUtils.to_hash(other)
20
+
21
+ return false if size == other.size
22
+
23
+ other.all? { |k, v| self[k] == v }
24
+ end
25
+
26
+ def >=(other)
27
+ other = InternalUtils.to_hash(other)
28
+
29
+ other.all? { |k, v| self[k] == v }
30
+ end
31
+
4
32
  def dig(head, *rest)
5
33
  [head, *rest].reduce(self) do |value, accessor|
6
34
  next_value =
@@ -1,4 +1,5 @@
1
1
  require_relative 'v2_5/dir'
2
+ require_relative 'v2_5/enumerable'
2
3
  require_relative 'v2_5/hash'
3
4
  require_relative 'v2_5/integer'
4
5
  require_relative 'v2_5/kernel'
@@ -0,0 +1,29 @@
1
+ module Polyfill
2
+ module V2_5
3
+ module Enumerable
4
+ def all?(*pattern)
5
+ return super if pattern.empty?
6
+
7
+ grep(*pattern).size == size
8
+ end
9
+
10
+ def any?(*pattern)
11
+ return super if pattern.empty?
12
+
13
+ !grep(*pattern).empty?
14
+ end
15
+
16
+ def none?(*pattern)
17
+ return super if pattern.empty?
18
+
19
+ grep(*pattern).empty?
20
+ end
21
+
22
+ def one?(*pattern)
23
+ return super if pattern.empty?
24
+
25
+ grep(*pattern).size == 1
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Polyfill
2
- VERSION = Gem::Version.new('1.2.0'.freeze)
2
+ VERSION = Gem::Version.new('1.3.0'.freeze)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyfill
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,6 +126,7 @@ files:
126
126
  - lib/polyfill/v2_5.rb
127
127
  - lib/polyfill/v2_5/big_decimal.rb
128
128
  - lib/polyfill/v2_5/dir.rb
129
+ - lib/polyfill/v2_5/enumerable.rb
129
130
  - lib/polyfill/v2_5/hash.rb
130
131
  - lib/polyfill/v2_5/integer.rb
131
132
  - lib/polyfill/v2_5/kernel.rb