ruby-next-core 1.1.2 → 1.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -1
- data/bin/transform +1 -1
- data/lib/.rbnext/2.1/ruby-next/commands/nextify.rb +1 -1
- data/lib/.rbnext/2.1/ruby-next/core.rb +2 -0
- data/lib/.rbnext/2.3/ruby-next/commands/core_ext.rb +4 -4
- data/lib/.rbnext/2.3/ruby-next/commands/nextify.rb +1 -1
- data/lib/.rbnext/2.3/ruby-next/config.rb +3 -2
- data/lib/.rbnext/2.7/ruby-next/core.rb +2 -0
- data/lib/.rbnext/2.7/ruby-next/language/rewriters/text.rb +1 -1
- data/lib/ruby-next/commands/core_ext.rb +4 -4
- data/lib/ruby-next/commands/nextify.rb +1 -1
- data/lib/ruby-next/config.rb +3 -2
- data/lib/ruby-next/core/array/rfind.rb +32 -0
- data/lib/ruby-next/core/enumerator/produce.rb +12 -4
- data/lib/ruby-next/core/refinement/import.rb +2 -2
- data/lib/ruby-next/core/string/strip.rb +138 -0
- data/lib/ruby-next/core.rb +2 -0
- data/lib/ruby-next/language/parser.rb +20 -2
- data/lib/ruby-next/language/rewriters/3.4/it_param.rb +26 -14
- data/lib/ruby-next/language/rewriters/text.rb +1 -1
- data/lib/ruby-next/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c2ad89ef94310a583c37c7499ba0821e47d6eff1011a1ae2b6fa8f069e55ca1
|
|
4
|
+
data.tar.gz: 61e2bdceb9d6244f90ef6a4d12d1b567a4caa6cf7f88169c948d42b178fc616c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4845fc1acabf1ecacdac7ac50118225bb1429e3cd5ba792a6200bbad08cac740026bffa50e4db5749be26053844940356697e0488b975da831ea9ac3a88ff032
|
|
7
|
+
data.tar.gz: 60851845387fe816df5ac182f118c3e8f521e30ee498d77b4ab464eae7d046132e1e5de9a185e9a59e82bc4fe4c692daa828f658b0d133ddd99708e6680ace91
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -45,7 +45,8 @@ Read more about the motivation behind the Ruby Next in this post: [Ruby Next: Ma
|
|
|
45
45
|
|
|
46
46
|
## Talks
|
|
47
47
|
|
|
48
|
-
- [Ruby
|
|
48
|
+
- [Ruby Mixology 101: adding shots of PHP, Elixir, and more](https://evilmartians.com/events/ruby-mixology-101) (RubyKaigi 2024)
|
|
49
|
+
- [Ruby Next: Make old Rubies quack like a new one](https://evilmartians.com/events/ruby-next-make-old-ruby-quack-like-a-new-one) (RubyConf 2019)
|
|
49
50
|
|
|
50
51
|
## Examples
|
|
51
52
|
|
data/bin/transform
CHANGED
|
@@ -147,7 +147,7 @@ module RubyNext
|
|
|
147
147
|
|
|
148
148
|
if print_rewriters
|
|
149
149
|
Language.rewriters.each do |rewriter|
|
|
150
|
-
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{
|
|
150
|
+
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{" (unsupported)" if rewriter.unsupported_syntax?}"
|
|
151
151
|
end
|
|
152
152
|
exit 0
|
|
153
153
|
end
|
|
@@ -160,10 +160,12 @@ require "ruby-next/core/enumerable/filter_map"
|
|
|
160
160
|
require "ruby-next/core/enumerator/produce"
|
|
161
161
|
|
|
162
162
|
require "ruby-next/core/array/difference_union_intersection"
|
|
163
|
+
require "ruby-next/core/array/rfind"
|
|
163
164
|
|
|
164
165
|
require "ruby-next/core/hash/merge"
|
|
165
166
|
|
|
166
167
|
require "ruby-next/core/string/split"
|
|
168
|
+
require "ruby-next/core/string/strip"
|
|
167
169
|
|
|
168
170
|
require "ruby-next/core/symbol/start_with"
|
|
169
171
|
require "ruby-next/core/symbol/end_with"
|
|
@@ -13,7 +13,7 @@ module RubyNext
|
|
|
13
13
|
|
|
14
14
|
def run
|
|
15
15
|
log "Select core extensions for Ruby v#{min_version}" \
|
|
16
|
-
"#{
|
|
16
|
+
"#{" and matching #{filter.inspect}" if filter}"
|
|
17
17
|
|
|
18
18
|
matching_patches.then do |patches|
|
|
19
19
|
next print_list(patches) if list?
|
|
@@ -70,9 +70,9 @@ module RubyNext
|
|
|
70
70
|
.values
|
|
71
71
|
.flatten
|
|
72
72
|
.select do |patch|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
next if min_version && Gem::Version.new(patch.version) <= min_version
|
|
74
|
+
next if filter && !filter.match?(patch.name)
|
|
75
|
+
true
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -147,7 +147,7 @@ module RubyNext
|
|
|
147
147
|
|
|
148
148
|
if print_rewriters
|
|
149
149
|
Language.rewriters.each do |rewriter|
|
|
150
|
-
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{
|
|
150
|
+
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{" (unsupported)" if rewriter.unsupported_syntax?}"
|
|
151
151
|
end
|
|
152
152
|
exit 0
|
|
153
153
|
end
|
|
@@ -10,10 +10,11 @@ module RubyNext
|
|
|
10
10
|
# Defines last minor version for every major version
|
|
11
11
|
LAST_MINOR_VERSIONS = {
|
|
12
12
|
2 => 8, # 2.8 is required for backward compatibility: some gems already uses it
|
|
13
|
-
3 =>
|
|
13
|
+
3 => 4,
|
|
14
|
+
4 => 0
|
|
14
15
|
}.freeze
|
|
15
16
|
|
|
16
|
-
LATEST_VERSION = [
|
|
17
|
+
LATEST_VERSION = [4, 0].freeze
|
|
17
18
|
|
|
18
19
|
# A virtual version number used for proposed features
|
|
19
20
|
NEXT_VERSION = "1995.next.0"
|
|
@@ -160,10 +160,12 @@ require "ruby-next/core/enumerable/filter_map"
|
|
|
160
160
|
require "ruby-next/core/enumerator/produce"
|
|
161
161
|
|
|
162
162
|
require "ruby-next/core/array/difference_union_intersection"
|
|
163
|
+
require "ruby-next/core/array/rfind"
|
|
163
164
|
|
|
164
165
|
require "ruby-next/core/hash/merge"
|
|
165
166
|
|
|
166
167
|
require "ruby-next/core/string/split"
|
|
168
|
+
require "ruby-next/core/string/strip"
|
|
167
169
|
|
|
168
170
|
require "ruby-next/core/symbol/start_with"
|
|
169
171
|
require "ruby-next/core/symbol/end_with"
|
|
@@ -13,7 +13,7 @@ module RubyNext
|
|
|
13
13
|
|
|
14
14
|
def run
|
|
15
15
|
log "Select core extensions for Ruby v#{min_version}" \
|
|
16
|
-
"#{
|
|
16
|
+
"#{" and matching #{filter.inspect}" if filter}"
|
|
17
17
|
|
|
18
18
|
matching_patches.then do |patches|
|
|
19
19
|
next print_list(patches) if list?
|
|
@@ -70,9 +70,9 @@ module RubyNext
|
|
|
70
70
|
.values
|
|
71
71
|
.flatten
|
|
72
72
|
.select do |patch|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
next if min_version && Gem::Version.new(patch.version) <= min_version
|
|
74
|
+
next if filter && !filter.match?(patch.name)
|
|
75
|
+
true
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -149,7 +149,7 @@ module RubyNext
|
|
|
149
149
|
|
|
150
150
|
if print_rewriters
|
|
151
151
|
Language.rewriters.each do |rewriter|
|
|
152
|
-
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{
|
|
152
|
+
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")#{" (unsupported)" if rewriter.unsupported_syntax?}"
|
|
153
153
|
end
|
|
154
154
|
exit 0
|
|
155
155
|
end
|
data/lib/ruby-next/config.rb
CHANGED
|
@@ -10,10 +10,11 @@ module RubyNext
|
|
|
10
10
|
# Defines last minor version for every major version
|
|
11
11
|
LAST_MINOR_VERSIONS = {
|
|
12
12
|
2 => 8, # 2.8 is required for backward compatibility: some gems already uses it
|
|
13
|
-
3 =>
|
|
13
|
+
3 => 4,
|
|
14
|
+
4 => 0
|
|
14
15
|
}.freeze
|
|
15
16
|
|
|
16
|
-
LATEST_VERSION = [
|
|
17
|
+
LATEST_VERSION = [4, 0].freeze
|
|
17
18
|
|
|
18
19
|
# A virtual version number used for proposed features
|
|
19
20
|
NEXT_VERSION = "1995.next.0"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RubyNext::Core.patch Array, method: :rfind, version: "4.0" do
|
|
4
|
+
<<-RUBY
|
|
5
|
+
def rfind(ifnone = nil)
|
|
6
|
+
unless block_given?
|
|
7
|
+
array = self
|
|
8
|
+
|
|
9
|
+
return Enumerator.new(size) do |yielder|
|
|
10
|
+
found = nil
|
|
11
|
+
matched = false
|
|
12
|
+
|
|
13
|
+
array.reverse_each do |element|
|
|
14
|
+
if yielder.yield(element)
|
|
15
|
+
found = element
|
|
16
|
+
matched = true
|
|
17
|
+
break
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
matched ? found : ifnone&.call
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
reverse_each do |element|
|
|
26
|
+
return element if yield(element)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
ifnone&.call
|
|
30
|
+
end
|
|
31
|
+
RUBY
|
|
32
|
+
end
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
RubyNext::Core.patch Enumerator.singleton_class, method: :produce, singleton: Enumerator,
|
|
3
|
+
RubyNext::Core.patch Enumerator.singleton_class, method: :produce, singleton: Enumerator,
|
|
4
|
+
supported: Enumerator.respond_to?(:produce) && (
|
|
5
|
+
begin
|
|
6
|
+
Enumerator.produce(a: 1, b: 1) {}
|
|
7
|
+
false
|
|
8
|
+
rescue ArgumentError
|
|
9
|
+
true
|
|
10
|
+
end
|
|
11
|
+
),
|
|
12
|
+
version: "4.0" do
|
|
4
13
|
<<-'RUBY'
|
|
5
|
-
|
|
6
|
-
def produce(*rest, &block)
|
|
14
|
+
def produce(*rest, size: Float::INFINITY, &block)
|
|
7
15
|
raise ArgumentError, "wrong number of arguments (given #{rest.size}, expected 0..1)" if rest.size > 1
|
|
8
16
|
raise ArgumentError, "No block given" unless block
|
|
9
17
|
|
|
10
|
-
Enumerator.new(
|
|
18
|
+
Enumerator.new(size) do |y|
|
|
11
19
|
val = rest.empty? ? yield() : rest.pop
|
|
12
20
|
|
|
13
21
|
loop do
|
|
@@ -56,12 +56,12 @@ RubyNext::Core.singleton_class.module_eval do
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
import.each do |(definition, file, lino)|
|
|
59
|
-
Kernel.eval definition, bind, file, lino
|
|
59
|
+
::Kernel.eval definition, bind, file, lino # rubocop:disable Security/Eval
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# Copy constants (they could be accessed from methods)
|
|
63
63
|
other.constants.each do |name|
|
|
64
|
-
Kernel.eval "#{name} = #{other}::#{name}", bind # rubocop:disable Style/EvalWithLocation
|
|
64
|
+
::Kernel.eval "#{name} = #{other}::#{name}", bind # rubocop:disable Style/EvalWithLocation,Security/Eval
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RubyNext::Core.patch String, name: "StringStripWithSelectors", method: :strip, version: "4.0", supported: String.instance_method(:strip).arity != 0, core_ext: :prepend do
|
|
4
|
+
<<-RUBY
|
|
5
|
+
def strip(*selectors)
|
|
6
|
+
return super() if selectors.empty?
|
|
7
|
+
|
|
8
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
9
|
+
return dup unless pattern
|
|
10
|
+
|
|
11
|
+
sub(/\\A[\#{pattern}]+/, "").tap { |str| str.sub!(/[\#{pattern}]+\\z/, "") }
|
|
12
|
+
end
|
|
13
|
+
RUBY
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
RubyNext::Core.patch String, name: "StringStripBangWithSelectors", method: :strip!, version: "4.0", supported: String.instance_method(:strip!).arity != 0, core_ext: :prepend do
|
|
17
|
+
<<-RUBY
|
|
18
|
+
def strip!(*selectors)
|
|
19
|
+
return super() if selectors.empty?
|
|
20
|
+
|
|
21
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
22
|
+
return dup unless pattern
|
|
23
|
+
|
|
24
|
+
original = dup
|
|
25
|
+
|
|
26
|
+
sub!(/\\A[\#{pattern}]+/, "")
|
|
27
|
+
sub!(/[\#{pattern}]+\\z/, "")
|
|
28
|
+
|
|
29
|
+
self == original ? nil : self
|
|
30
|
+
end
|
|
31
|
+
RUBY
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
RubyNext::Core.patch String, name: "StringLstripWithSelectors", method: :lstrip, version: "4.0", supported: String.instance_method(:lstrip).arity != 0, core_ext: :prepend do
|
|
35
|
+
<<-RUBY
|
|
36
|
+
def lstrip(*selectors)
|
|
37
|
+
return super() if selectors.empty?
|
|
38
|
+
|
|
39
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
40
|
+
return dup unless pattern
|
|
41
|
+
|
|
42
|
+
sub(/\\A[\#{pattern}]+/, "")
|
|
43
|
+
end
|
|
44
|
+
RUBY
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
RubyNext::Core.patch String, name: "StringLstripBangWithSelectors", method: :lstrip!, version: "4.0", supported: String.instance_method(:lstrip!).arity != 0, core_ext: :prepend do
|
|
48
|
+
<<-RUBY
|
|
49
|
+
def lstrip!(*selectors)
|
|
50
|
+
return super() if selectors.empty?
|
|
51
|
+
|
|
52
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
53
|
+
return dup unless pattern
|
|
54
|
+
|
|
55
|
+
sub!(/\\A[\#{pattern}]+/, "")
|
|
56
|
+
end
|
|
57
|
+
RUBY
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
RubyNext::Core.patch String, name: "StringRstripWithSelectors", method: :rstrip, version: "4.0", supported: String.instance_method(:rstrip).arity != 0, core_ext: :prepend do
|
|
61
|
+
<<-RUBY
|
|
62
|
+
def rstrip(*selectors)
|
|
63
|
+
return super() if selectors.empty?
|
|
64
|
+
|
|
65
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
66
|
+
return dup unless pattern
|
|
67
|
+
|
|
68
|
+
sub(/[\#{pattern}]+\\z/, "")
|
|
69
|
+
end
|
|
70
|
+
RUBY
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
RubyNext::Core.patch String, name: "StringRstripBangWithSelectors", method: :rstrip!, version: "4.0", supported: String.instance_method(:rstrip!).arity != 0, core_ext: :prepend do
|
|
74
|
+
<<-RUBY
|
|
75
|
+
def rstrip!(*selectors)
|
|
76
|
+
return super() if selectors.empty?
|
|
77
|
+
|
|
78
|
+
pattern = RubyNext::Core::StringStripSelectors.build_pattern(selectors)
|
|
79
|
+
return dup unless pattern
|
|
80
|
+
|
|
81
|
+
sub!(/[\#{pattern}]+\\z/, "")
|
|
82
|
+
end
|
|
83
|
+
RUBY
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
module RubyNext
|
|
87
|
+
module Core
|
|
88
|
+
module StringStripSelectors
|
|
89
|
+
# Converts selector strings (like "0-9", "^a-z", "abc") into a regex character class pattern.
|
|
90
|
+
# For multiple selectors, we need to handle intersection/negation
|
|
91
|
+
def self.build_pattern(selectors)
|
|
92
|
+
selectors.each { |selector| raise TypeError, "no implicit conversion of #{selector} into String" unless selector.respond_to?(:to_str) }
|
|
93
|
+
|
|
94
|
+
if selectors.length == 1
|
|
95
|
+
selector = selectors[0].to_str
|
|
96
|
+
if selector.start_with?("^")
|
|
97
|
+
char_class = escape_for_char_class(selector[1..-1])
|
|
98
|
+
"[^#{char_class}]"
|
|
99
|
+
elsif !selector.empty?
|
|
100
|
+
char_class = escape_for_char_class(selector)
|
|
101
|
+
"[#{char_class}]"
|
|
102
|
+
end
|
|
103
|
+
else
|
|
104
|
+
positive = []
|
|
105
|
+
negative = []
|
|
106
|
+
|
|
107
|
+
selectors.each do |s|
|
|
108
|
+
str = s.to_str
|
|
109
|
+
if str.start_with?("^")
|
|
110
|
+
negative << escape_for_char_class(str[1..-1])
|
|
111
|
+
elsif !str.empty?
|
|
112
|
+
positive << escape_for_char_class(str)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if positive.any? && negative.any?
|
|
117
|
+
pos_class = positive.join
|
|
118
|
+
neg_class = negative.join
|
|
119
|
+
"[#{pos_class}&&[^#{neg_class}]]"
|
|
120
|
+
elsif positive.any?
|
|
121
|
+
"[#{positive.join}]"
|
|
122
|
+
elsif negative.any?
|
|
123
|
+
"[^#{negative.join}]"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.escape_for_char_class(selector)
|
|
129
|
+
str = selector.to_str
|
|
130
|
+
|
|
131
|
+
# Escape special characters but preserve ranges
|
|
132
|
+
# Inside character class: need to escape ] \ ^
|
|
133
|
+
# - is special only between characters (part of range)
|
|
134
|
+
str.gsub(/(?<!^)([\]\\\^])/) { "\\#{$1}" }
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
data/lib/ruby-next/core.rb
CHANGED
|
@@ -160,10 +160,12 @@ require "ruby-next/core/enumerable/filter_map"
|
|
|
160
160
|
require "ruby-next/core/enumerator/produce"
|
|
161
161
|
|
|
162
162
|
require "ruby-next/core/array/difference_union_intersection"
|
|
163
|
+
require "ruby-next/core/array/rfind"
|
|
163
164
|
|
|
164
165
|
require "ruby-next/core/hash/merge"
|
|
165
166
|
|
|
166
167
|
require "ruby-next/core/string/split"
|
|
168
|
+
require "ruby-next/core/string/strip"
|
|
167
169
|
|
|
168
170
|
require "ruby-next/core/symbol/start_with"
|
|
169
171
|
require "ruby-next/core/symbol/end_with"
|
|
@@ -34,11 +34,26 @@ module RubyNext
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
if defined?(::Prism::Translation::Parser::Builder)
|
|
38
|
+
class PrismBuilder < ::Prism::Translation::Parser::Builder
|
|
39
|
+
modernize
|
|
40
|
+
|
|
41
|
+
unless method_defined?(:match_pattern_p)
|
|
42
|
+
include BuilderExt
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def check_reserved_for_numparam(name, loc)
|
|
46
|
+
# We don't want to raise SyntaxError, 'cause we want to use _x vars for older Rubies.
|
|
47
|
+
# The exception should be raised by Ruby itself for versions supporting numbered parameters
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
37
52
|
class << self
|
|
38
|
-
attr_accessor :parser_class, :parser_syntax_errors
|
|
53
|
+
attr_accessor :parser_class, :parser_syntax_errors, :builder_class
|
|
39
54
|
|
|
40
55
|
def parser
|
|
41
|
-
parser_class.new(
|
|
56
|
+
parser_class.new(builder_class.new).tap do |prs|
|
|
42
57
|
prs.diagnostics.tap do |diagnostics|
|
|
43
58
|
diagnostics.all_errors_are_fatal = true
|
|
44
59
|
end
|
|
@@ -67,6 +82,7 @@ module RubyNext
|
|
|
67
82
|
end
|
|
68
83
|
|
|
69
84
|
self.parser_syntax_errors = [::Parser::SyntaxError]
|
|
85
|
+
self.builder_class = Builder
|
|
70
86
|
|
|
71
87
|
# Set up default parser
|
|
72
88
|
unless parser_class
|
|
@@ -82,6 +98,8 @@ module RubyNext
|
|
|
82
98
|
end
|
|
83
99
|
end.tap do |clazz|
|
|
84
100
|
Language.const_set(:PrismParser, clazz)
|
|
101
|
+
|
|
102
|
+
self.builder_class = PrismBuilder
|
|
85
103
|
end
|
|
86
104
|
else
|
|
87
105
|
::Parser::Ruby34
|
|
@@ -11,29 +11,41 @@ module RubyNext
|
|
|
11
11
|
MIN_SUPPORTED_VERSION = Gem::Version.new("3.4.0")
|
|
12
12
|
|
|
13
13
|
def on_block(node)
|
|
14
|
-
|
|
14
|
+
_proc_or_lambda, _args, body = *node.children
|
|
15
15
|
|
|
16
16
|
return super unless block_has_it?(body)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
process_block(node)
|
|
19
|
+
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
body)
|
|
21
|
+
def on_itblock(node)
|
|
22
|
+
_proc_or_lambda, _args, body = *node.children
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
return super unless block_has_it?(body)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
node.updated(:numblock, [
|
|
28
|
-
proc_or_lambda,
|
|
29
|
-
args,
|
|
30
|
-
new_body
|
|
31
|
-
])
|
|
32
|
-
)
|
|
26
|
+
process_block(node)
|
|
33
27
|
end
|
|
34
28
|
|
|
35
29
|
private
|
|
36
30
|
|
|
31
|
+
def process_block(node)
|
|
32
|
+
context.track! self
|
|
33
|
+
|
|
34
|
+
proc_or_lambda, _args, body = *node.children
|
|
35
|
+
|
|
36
|
+
if proc_or_lambda.type == :lambda
|
|
37
|
+
insert_before(node.loc.begin, "(it)")
|
|
38
|
+
else
|
|
39
|
+
insert_after(node.loc.begin, " |it|")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
node.updated(:block, [
|
|
43
|
+
proc_or_lambda,
|
|
44
|
+
s(:args, s(:procarg0, s(:arg, :it))),
|
|
45
|
+
process(body)
|
|
46
|
+
])
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
# It's important to check if the current block refers to `it` variable somewhere
|
|
38
50
|
# (and not within a nested block), so we don't declare numbered params
|
|
39
51
|
def block_has_it?(node)
|
|
@@ -44,7 +56,7 @@ module RubyNext
|
|
|
44
56
|
return true if it?(child)
|
|
45
57
|
|
|
46
58
|
if child.is_a?(Parser::AST::Node)
|
|
47
|
-
tree.unshift(*child.children.select { |c| c.is_a?(Parser::AST::Node) && c.type != :block && c.type != :numblock })
|
|
59
|
+
tree.unshift(*child.children.select { |c| c.is_a?(Parser::AST::Node) && c.type != :block && c.type != :numblock && c.type != :itblock })
|
|
48
60
|
end
|
|
49
61
|
end
|
|
50
62
|
end
|
data/lib/ruby-next/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-next-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vladimir Dementyev
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: require-hooks
|
|
@@ -118,6 +117,7 @@ files:
|
|
|
118
117
|
- lib/ruby-next/core/array/deconstruct.rb
|
|
119
118
|
- lib/ruby-next/core/array/difference_union_intersection.rb
|
|
120
119
|
- lib/ruby-next/core/array/intersect.rb
|
|
120
|
+
- lib/ruby-next/core/array/rfind.rb
|
|
121
121
|
- lib/ruby-next/core/constants/frozen_error.rb
|
|
122
122
|
- lib/ruby-next/core/constants/no_matching_pattern_error.rb
|
|
123
123
|
- lib/ruby-next/core/data.rb
|
|
@@ -139,6 +139,7 @@ files:
|
|
|
139
139
|
- lib/ruby-next/core/refinement/import.rb
|
|
140
140
|
- lib/ruby-next/core/runtime.rb
|
|
141
141
|
- lib/ruby-next/core/string/split.rb
|
|
142
|
+
- lib/ruby-next/core/string/strip.rb
|
|
142
143
|
- lib/ruby-next/core/struct/deconstruct.rb
|
|
143
144
|
- lib/ruby-next/core/struct/deconstruct_keys.rb
|
|
144
145
|
- lib/ruby-next/core/symbol/end_with.rb
|
|
@@ -209,7 +210,6 @@ metadata:
|
|
|
209
210
|
homepage_uri: https://github.com/ruby-next/ruby-next
|
|
210
211
|
source_code_uri: https://github.com/ruby-next/ruby-next
|
|
211
212
|
funding_uri: https://github.com/sponsors/palkan
|
|
212
|
-
post_install_message:
|
|
213
213
|
rdoc_options: []
|
|
214
214
|
require_paths:
|
|
215
215
|
- lib
|
|
@@ -224,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
224
224
|
- !ruby/object:Gem::Version
|
|
225
225
|
version: '0'
|
|
226
226
|
requirements: []
|
|
227
|
-
rubygems_version: 3.
|
|
228
|
-
signing_key:
|
|
227
|
+
rubygems_version: 3.6.9
|
|
229
228
|
specification_version: 4
|
|
230
229
|
summary: Ruby Next core functionality
|
|
231
230
|
test_files: []
|