Skip to content

Commit

Permalink
[GR-19220] Add alias String#dedup to String#-@ for Ruby v3.2
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3818
  • Loading branch information
andrykonchin committed May 23, 2023
2 parents dc94263 + 5fd286c commit bfbc036
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Bug fixes:

Compatibility:

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

Performance:

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/string/dedup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative 'shared/dedup'

describe 'String#dedup' do
ruby_version_is '3.2'do
ruby_version_is '3.2' do
it_behaves_like :string_dedup, :dedup
end
end
1 change: 1 addition & 0 deletions spec/tags/core/string/dedup_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:String#dedup interns the provided string if it is frozen
1 change: 1 addition & 0 deletions spec/truffle/methods/String.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ codepoints
concat
count
crypt
dedup
delete
delete!
delete_prefix
Expand Down
2 changes: 2 additions & 0 deletions spec/truffleruby.next-specs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ spec/ruby/core/array/element_reference_spec.rb

spec/ruby/core/hash/shift_spec.rb
spec/ruby/core/range/size_spec.rb

spec/ruby/core/string/dedup_spec.rb
2 changes: 1 addition & 1 deletion src/main/java/org/truffleruby/parser/BodyTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public RubyNode visitCallNode(CallParseNode node) {
final String methodName = node.getName();

if (receiver instanceof StrParseNode &&
(methodName.equals("freeze") || methodName.equals("-@"))) {
(methodName.equals("freeze") || methodName.equals("-@") || methodName.equals("dedup"))) {
final StrParseNode strNode = (StrParseNode) receiver;
final TruffleString tstring = strNode.getValue();
final ImmutableRubyString frozenString = language.getFrozenStringLiteral(tstring, strNode.encoding);
Expand Down
1 change: 1 addition & 0 deletions src/main/ruby/truffleruby/core/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ def -@
Primitive.string_intern(str)
end
end
alias_method :dedup, :-@

def <=>(other)
if Primitive.is_a?(other, String)
Expand Down
4 changes: 4 additions & 0 deletions src/main/ruby/truffleruby/core/truffle/polyglot_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def crypt(...)
to_s.crypt(...)
end

def dedup(...)
to_s.dedup(...)
end

def delete(...)
to_s.delete(...)
end
Expand Down

0 comments on commit bfbc036

Please sign in to comment.