polyfill 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +31 -2
- data/CONTRIBUTING.md +48 -17
- data/README.md +110 -80
- data/Rakefile +3 -1
- data/bin/console +3 -3
- data/lib/polyfill.rb +30 -19
- data/lib/polyfill/v2_4.rb +29 -12
- data/lib/polyfill/v2_4/array.rb +1 -1
- data/lib/polyfill/v2_4/array/instance.rb +3 -1
- data/lib/polyfill/v2_4/array/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/array/instance/sum.rb +17 -0
- data/lib/polyfill/v2_4/comparable.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance/clamp.rb +11 -13
- data/lib/polyfill/v2_4/dir.rb +1 -1
- data/lib/polyfill/v2_4/dir/class.rb +1 -1
- data/lib/polyfill/v2_4/dir/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/enumerable.rb +9 -0
- data/lib/polyfill/v2_4/enumerable/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +46 -0
- data/lib/polyfill/v2_4/enumerable/instance/sum.rb +52 -0
- data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +45 -0
- data/lib/polyfill/v2_4/enumerator/lazy.rb +11 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +25 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb +33 -0
- data/lib/polyfill/v2_4/file.rb +1 -1
- data/lib/polyfill/v2_4/file/class.rb +1 -1
- data/lib/polyfill/v2_4/file/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/float.rb +1 -1
- data/lib/polyfill/v2_4/float/instance.rb +3 -3
- data/lib/polyfill/v2_4/float/instance/ceil.rb +8 -10
- data/lib/polyfill/v2_4/float/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/float/instance/truncate.rb +8 -10
- data/lib/polyfill/v2_4/hash.rb +1 -1
- data/lib/polyfill/v2_4/hash/instance.rb +4 -4
- data/lib/polyfill/v2_4/hash/instance/compact.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/compact_e.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/transform_values.rb +6 -8
- data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +6 -8
- data/lib/polyfill/v2_4/i_p_addr.rb +9 -0
- data/lib/polyfill/v2_4/i_p_addr/instance.rb +13 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/equalequal.rb +27 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/lessthanequalgreaterthan.rb +27 -0
- data/lib/polyfill/v2_4/integer.rb +1 -1
- data/lib/polyfill/v2_4/integer/instance.rb +5 -5
- data/lib/polyfill/v2_4/integer/instance/ceil.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/digits.rb +5 -7
- data/lib/polyfill/v2_4/integer/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/round.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/truncate.rb +7 -9
- data/lib/polyfill/v2_4/io.rb +2 -2
- data/lib/polyfill/v2_4/io/class.rb +2 -2
- data/lib/polyfill/v2_4/io/class/foreach.rb +21 -33
- data/lib/polyfill/v2_4/io/class/readlines.rb +12 -13
- data/lib/polyfill/v2_4/io/instance.rb +6 -4
- data/lib/polyfill/v2_4/io/instance/each_line.rb +20 -33
- data/lib/polyfill/v2_4/io/instance/gets.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/lines.rb +54 -0
- data/lib/polyfill/v2_4/io/instance/readline.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/readlines.rb +12 -13
- data/lib/polyfill/v2_4/match_data.rb +1 -1
- data/lib/polyfill/v2_4/match_data/instance.rb +2 -2
- data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +5 -7
- data/lib/polyfill/v2_4/match_data/instance/values_at.rb +5 -7
- data/lib/polyfill/v2_4/numeric.rb +1 -1
- data/lib/polyfill/v2_4/numeric/instance.rb +6 -2
- data/lib/polyfill/v2_4/numeric/instance/clone.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/dup.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +5 -7
- data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +5 -7
- data/lib/polyfill/v2_4/object.rb +9 -0
- data/lib/polyfill/v2_4/object/instance.rb +11 -0
- data/lib/polyfill/v2_4/object/instance/clone.rb +29 -0
- data/lib/polyfill/v2_4/pathname.rb +9 -0
- data/lib/polyfill/v2_4/pathname/instance.rb +11 -0
- data/lib/polyfill/v2_4/pathname/instance/empty_q.rb +29 -0
- data/lib/polyfill/v2_4/regexp.rb +9 -0
- data/lib/polyfill/v2_4/regexp/instance.rb +11 -0
- data/lib/polyfill/v2_4/regexp/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string.rb +3 -1
- data/lib/polyfill/v2_4/string/class.rb +11 -0
- data/lib/polyfill/v2_4/string/class/new.rb +26 -0
- data/lib/polyfill/v2_4/string/instance.rb +12 -2
- data/lib/polyfill/v2_4/string/instance/casecmp_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/each_line.rb +17 -0
- data/lib/polyfill/v2_4/string/instance/lines.rb +55 -0
- data/lib/polyfill/v2_4/string/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/prepend.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/unpack1.rb +23 -0
- data/lib/polyfill/v2_4/string_io.rb +1 -1
- data/lib/polyfill/v2_4/string_io/instance.rb +4 -4
- data/lib/polyfill/v2_4/string_io/instance/each_line.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/gets.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readline.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readlines.rb +5 -7
- data/lib/polyfill/v2_4/symbol.rb +9 -0
- data/lib/polyfill/v2_4/symbol/instance.rb +15 -0
- data/lib/polyfill/v2_4/symbol/instance/casecmp_q.rb +25 -0
- data/lib/polyfill/v2_4/symbol/instance/match.rb +27 -0
- data/lib/polyfill/v2_4/symbol/instance/match_q.rb +17 -0
- data/lib/polyfill/version.rb +1 -1
- data/polyfill.gemspec +1 -0
- metadata +56 -3
data/lib/polyfill/v2_4.rb
CHANGED
@@ -1,29 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
require_relative 'v2_4/enumerable'
|
2
|
+
require_relative 'v2_4/array'
|
3
|
+
require_relative 'v2_4/comparable'
|
4
|
+
require_relative 'v2_4/dir'
|
5
|
+
require_relative 'v2_4/enumerator/lazy'
|
6
|
+
require_relative 'v2_4/file'
|
7
|
+
require_relative 'v2_4/float'
|
8
|
+
require_relative 'v2_4/hash'
|
9
|
+
require_relative 'v2_4/integer'
|
10
|
+
require_relative 'v2_4/io'
|
11
|
+
require_relative 'v2_4/match_data'
|
12
|
+
require_relative 'v2_4/numeric'
|
13
|
+
require_relative 'v2_4/object'
|
14
|
+
require_relative 'v2_4/regexp'
|
15
|
+
require_relative 'v2_4/string'
|
16
|
+
require_relative 'v2_4/string_io'
|
17
|
+
require_relative 'v2_4/symbol'
|
18
|
+
|
19
|
+
require_relative 'v2_4/i_p_addr'
|
20
|
+
require_relative 'v2_4/pathname'
|
13
21
|
|
14
22
|
module Polyfill
|
15
23
|
module V2_4
|
16
24
|
include Array
|
17
25
|
include Comparable
|
18
26
|
include Dir
|
27
|
+
include Enumerable
|
28
|
+
include Enumerator::Lazy
|
19
29
|
include File
|
20
30
|
include Float
|
21
31
|
include Hash
|
22
32
|
include Integer
|
23
33
|
include IO
|
34
|
+
include Kernel
|
24
35
|
include MatchData
|
25
36
|
include Numeric
|
37
|
+
include Object
|
38
|
+
include Regexp
|
26
39
|
include String
|
27
40
|
include StringIO
|
41
|
+
include Symbol
|
42
|
+
|
43
|
+
include IPAddr
|
44
|
+
include Pathname
|
28
45
|
end
|
29
46
|
end
|
data/lib/polyfill/v2_4/array.rb
CHANGED
@@ -16,14 +16,12 @@ module Polyfill
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
refine ::Array do
|
20
|
+
include Method
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
def self.included(base)
|
24
|
+
base.include Method
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Array
|
4
|
+
module Instance
|
5
|
+
module Sum
|
6
|
+
refine ::Array do
|
7
|
+
include Enumerable::Instance::Sum::Method
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.include Enumerable::Instance::Sum::Method
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -15,20 +15,18 @@ module Polyfill
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
18
|
+
refine ::Numeric do
|
19
|
+
include Method
|
20
|
+
end
|
21
|
+
refine ::String do
|
22
|
+
include Method
|
23
|
+
end
|
24
|
+
refine ::Time do
|
25
|
+
include Method
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
28
|
+
def self.included(base)
|
29
|
+
base.include Method
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
data/lib/polyfill/v2_4/dir.rb
CHANGED
@@ -9,14 +9,12 @@ module Polyfill
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
refine ::Dir.singleton_class do
|
13
|
+
include Method
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Enumerable
|
4
|
+
module Instance
|
5
|
+
module Chunk
|
6
|
+
module Method
|
7
|
+
def chunk(*)
|
8
|
+
return enum_for(:chunk) unless block_given?
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
refine ::Array do
|
15
|
+
include Method
|
16
|
+
end
|
17
|
+
refine ::Dir do
|
18
|
+
include Method
|
19
|
+
end
|
20
|
+
refine ::Enumerator do
|
21
|
+
include Method
|
22
|
+
end
|
23
|
+
refine ::Hash do
|
24
|
+
include Method
|
25
|
+
end
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
refine ::Range do
|
30
|
+
include Method
|
31
|
+
end
|
32
|
+
refine ::StringIO do
|
33
|
+
include Method
|
34
|
+
end
|
35
|
+
refine ::Struct do
|
36
|
+
include Method
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.included(base)
|
40
|
+
base.include Method
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Enumerable
|
4
|
+
module Instance
|
5
|
+
module Sum
|
6
|
+
module Method
|
7
|
+
def sum(init = 0)
|
8
|
+
acc =
|
9
|
+
begin
|
10
|
+
init.dup
|
11
|
+
rescue TypeError
|
12
|
+
init
|
13
|
+
end
|
14
|
+
|
15
|
+
each do |elem|
|
16
|
+
acc += block_given? ? yield(elem) : elem
|
17
|
+
end
|
18
|
+
|
19
|
+
acc
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
refine ::Dir do
|
24
|
+
include Method
|
25
|
+
end
|
26
|
+
refine ::Enumerator do
|
27
|
+
include Method
|
28
|
+
end
|
29
|
+
refine ::Hash do
|
30
|
+
include Method
|
31
|
+
end
|
32
|
+
refine ::IO do
|
33
|
+
include Method
|
34
|
+
end
|
35
|
+
refine ::Range do
|
36
|
+
include Method
|
37
|
+
end
|
38
|
+
refine ::StringIO do
|
39
|
+
include Method
|
40
|
+
end
|
41
|
+
refine ::Struct do
|
42
|
+
include Method
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.included(base)
|
46
|
+
base.include Method
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Enumerable
|
4
|
+
module Instance
|
5
|
+
module Uniq
|
6
|
+
module Method
|
7
|
+
def uniq
|
8
|
+
if block_given?
|
9
|
+
to_a.uniq(&Proc.new)
|
10
|
+
else
|
11
|
+
to_a.uniq
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
refine ::Dir do
|
17
|
+
include Method
|
18
|
+
end
|
19
|
+
refine ::Enumerator do
|
20
|
+
include Method
|
21
|
+
end
|
22
|
+
refine ::Hash do
|
23
|
+
include Method
|
24
|
+
end
|
25
|
+
refine ::IO do
|
26
|
+
include Method
|
27
|
+
end
|
28
|
+
refine ::Range do
|
29
|
+
include Method
|
30
|
+
end
|
31
|
+
refine ::StringIO do
|
32
|
+
include Method
|
33
|
+
end
|
34
|
+
refine ::Struct do
|
35
|
+
include Method
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.included(base)
|
39
|
+
base.include Method
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_4
|
3
|
+
module Enumerator
|
4
|
+
module Lazy
|
5
|
+
module Instance
|
6
|
+
module ChunkWhile
|
7
|
+
module Method
|
8
|
+
def chunk_while
|
9
|
+
super.lazy
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
refine ::Enumerator::Lazy 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,33 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_4
|
5
|
+
module Enumerator
|
6
|
+
module Lazy
|
7
|
+
module Instance
|
8
|
+
module Uniq
|
9
|
+
module Method
|
10
|
+
def uniq
|
11
|
+
seen = Set.new
|
12
|
+
|
13
|
+
::Enumerator::Lazy.new(self) do |yielder, *values|
|
14
|
+
result = block_given? ? yield(*values) : values
|
15
|
+
|
16
|
+
yielder.<<(*values) if seen.add?(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
refine ::Enumerator::Lazy 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
|