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
@@ -12,19 +12,17 @@ module Polyfill
|
|
12
12
|
return super() if ndigits == 0
|
13
13
|
return to_f if ndigits > 0
|
14
14
|
|
15
|
-
place = 10
|
16
|
-
(
|
15
|
+
place = 10**-ndigits
|
16
|
+
(to_f / place).round * place
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
refine ::Integer do
|
21
|
+
include Method
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
def self.included(base)
|
25
|
+
base.include Method
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -9,19 +9,17 @@ module Polyfill
|
|
9
9
|
return super() if ndigits == 0
|
10
10
|
return to_f if ndigits > 0
|
11
11
|
|
12
|
-
place = 10
|
13
|
-
(
|
12
|
+
place = 10**-ndigits
|
13
|
+
(to_f / place).truncate * place
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
refine ::Integer do
|
18
|
+
include Method
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
def self.included(base)
|
22
|
+
base.include Method
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/polyfill/v2_4/io.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -6,42 +8,30 @@ module Polyfill
|
|
6
8
|
module Method
|
7
9
|
def foreach(name, *args)
|
8
10
|
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
-
|
10
11
|
chomps = hash[0] && hash[0][:chomp]
|
11
12
|
|
12
13
|
unless block_given?
|
13
|
-
|
14
|
-
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
return super(name, *others) unless chomps
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
Proc.new do |line|
|
24
|
-
yielder.yield(line.chomp)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
super(name, *others, &block)
|
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))
|
28
23
|
end
|
29
|
-
else
|
30
|
-
return super(name, *others)
|
31
24
|
end
|
32
25
|
end
|
33
26
|
|
34
27
|
block =
|
35
28
|
if chomps
|
36
|
-
separator = others.find
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Proc.new do |line|
|
43
|
-
yield(line.chomp)
|
44
|
-
end
|
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))
|
45
35
|
end
|
46
36
|
else
|
47
37
|
Proc.new
|
@@ -51,14 +41,12 @@ module Polyfill
|
|
51
41
|
end
|
52
42
|
end
|
53
43
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
44
|
+
refine ::IO.singleton_class do
|
45
|
+
include Method
|
46
|
+
end
|
58
47
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
48
|
+
def self.included(base)
|
49
|
+
base.include Method
|
62
50
|
end
|
63
51
|
end
|
64
52
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -10,26 +12,23 @@ module Polyfill
|
|
10
12
|
inputs = super(file_name, *others)
|
11
13
|
|
12
14
|
if hash[0] && hash[0][:chomp]
|
13
|
-
separator = others.find
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
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) }
|
19
20
|
end
|
20
21
|
|
21
22
|
inputs
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
refine ::IO.singleton_class do
|
27
|
+
include Method
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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'
|
5
6
|
|
6
7
|
module Polyfill
|
7
8
|
module V2_4
|
@@ -9,6 +10,7 @@ module Polyfill
|
|
9
10
|
module Instance
|
10
11
|
include EachLine
|
11
12
|
include Gets
|
13
|
+
include Lines
|
12
14
|
include Readline
|
13
15
|
include Readlines
|
14
16
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -6,42 +8,29 @@ module Polyfill
|
|
6
8
|
module Method
|
7
9
|
def each_line(*args)
|
8
10
|
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
-
|
10
11
|
chomps = hash[0] && hash[0][:chomp]
|
11
12
|
|
12
13
|
unless block_given?
|
13
|
-
|
14
|
-
separator = others.find { |other| other.respond_to?(:to_str) }
|
14
|
+
return super(*others) unless chomps
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
Proc.new do |line|
|
24
|
-
yielder.yield(line.chomp)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
super(*others, &block)
|
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))
|
28
22
|
end
|
29
|
-
else
|
30
|
-
return super(*others)
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
26
|
block =
|
35
27
|
if chomps
|
36
|
-
separator = others.find
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Proc.new do |line|
|
43
|
-
yield(line.chomp)
|
44
|
-
end
|
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))
|
45
34
|
end
|
46
35
|
else
|
47
36
|
Proc.new
|
@@ -51,14 +40,12 @@ module Polyfill
|
|
51
40
|
end
|
52
41
|
end
|
53
42
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
43
|
+
refine ::IO do
|
44
|
+
include Method
|
45
|
+
end
|
58
46
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
47
|
+
def self.included(base)
|
48
|
+
base.include Method
|
62
49
|
end
|
63
50
|
end
|
64
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -10,26 +12,23 @@ module Polyfill
|
|
10
12
|
input = super(*others)
|
11
13
|
|
12
14
|
if !input.nil? && hash[0] && hash[0][:chomp]
|
13
|
-
separator = others.find
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
separator = others.find do |other|
|
16
|
+
other.respond_to?(:to_str)
|
17
|
+
end || $INPUT_RECORD_SEPARATOR
|
18
|
+
|
19
|
+
input.chomp!(separator)
|
19
20
|
end
|
20
21
|
|
21
22
|
input
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -0,0 +1,54 @@
|
|
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,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -10,26 +12,23 @@ module Polyfill
|
|
10
12
|
input = super(*others)
|
11
13
|
|
12
14
|
if hash[0] && hash[0][:chomp]
|
13
|
-
separator = others.find
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
separator = others.find do |other|
|
16
|
+
other.respond_to?(:to_str)
|
17
|
+
end || $INPUT_RECORD_SEPARATOR
|
18
|
+
|
19
|
+
input.chomp!(separator)
|
19
20
|
end
|
20
21
|
|
21
22
|
input
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module Polyfill
|
2
4
|
module V2_4
|
3
5
|
module IO
|
@@ -10,26 +12,23 @@ module Polyfill
|
|
10
12
|
inputs = super(*others)
|
11
13
|
|
12
14
|
if hash[0] && hash[0][:chomp]
|
13
|
-
separator = others.find
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
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) }
|
19
20
|
end
|
20
21
|
|
21
22
|
inputs
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
refine ::IO do
|
27
|
+
include Method
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
def self.included(base)
|
31
|
+
base.include Method
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|