Skip to content

Commit bfbc036

Browse files
committed
[GR-19220] Add alias String#dedup to String#-@ for Ruby v3.2
PullRequest: truffleruby/3818
2 parents dc94263 + 5fd286c commit bfbc036

File tree

8 files changed

+15
-5
lines changed

8 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ Bug fixes:
88

99
Compatibility:
1010

11-
* Fix `Hash#shift` when Hash is empty but has initial default value or initial default proc (@itarato).
11+
* Fix `Hash#shift` when Hash is empty but has initial default value or initial default proc (#3039, @itarato).
1212
* Make `Array#shuffle` produce the same results as CRuby (@rwstauner).
1313
* Add `Process.argv0` method (@andrykonchin).
1414
* Add support for array pattern matching. This is opt-in via `--pattern-matching` since pattern matching is not fully supported yet. (#2683, @razetime).
15-
* Fix `Array#[]` with `ArithmeticSequence` argument when step is negative (@itarato).
16-
* Fix `Range#size` and return `nil` for beginningless Range when end isn't Numeric (@rwstauner).
15+
* Fix `Array#[]` with `ArithmeticSequence` argument when step is negative (#3039, @itarato).
16+
* Fix `Range#size` and return `nil` for beginningless Range when end isn't Numeric (#3039, @rwstauner).
17+
* Alias `String#-@` to `String#dedup` (#3039, @itarato).
1718

1819
Performance:
1920

spec/ruby/core/string/dedup_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require_relative 'shared/dedup'
33

44
describe 'String#dedup' do
5-
ruby_version_is '3.2'do
5+
ruby_version_is '3.2' do
66
it_behaves_like :string_dedup, :dedup
77
end
88
end

spec/tags/core/string/dedup_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fails:String#dedup interns the provided string if it is frozen

spec/truffle/methods/String.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ codepoints
3131
concat
3232
count
3333
crypt
34+
dedup
3435
delete
3536
delete!
3637
delete_prefix

spec/truffleruby.next-specs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ spec/ruby/core/array/element_reference_spec.rb
1414

1515
spec/ruby/core/hash/shift_spec.rb
1616
spec/ruby/core/range/size_spec.rb
17+
18+
spec/ruby/core/string/dedup_spec.rb

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public RubyNode visitCallNode(CallParseNode node) {
491491
final String methodName = node.getName();
492492

493493
if (receiver instanceof StrParseNode &&
494-
(methodName.equals("freeze") || methodName.equals("-@"))) {
494+
(methodName.equals("freeze") || methodName.equals("-@") || methodName.equals("dedup"))) {
495495
final StrParseNode strNode = (StrParseNode) receiver;
496496
final TruffleString tstring = strNode.getValue();
497497
final ImmutableRubyString frozenString = language.getFrozenStringLiteral(tstring, strNode.encoding);

src/main/ruby/truffleruby/core/string.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ def -@
12321232
Primitive.string_intern(str)
12331233
end
12341234
end
1235+
alias_method :dedup, :-@
12351236

12361237
def <=>(other)
12371238
if Primitive.is_a?(other, String)

src/main/ruby/truffleruby/core/truffle/polyglot_methods.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def crypt(...)
148148
to_s.crypt(...)
149149
end
150150

151+
def dedup(...)
152+
to_s.dedup(...)
153+
end
154+
151155
def delete(...)
152156
to_s.delete(...)
153157
end

0 commit comments

Comments
 (0)