Skip to content

Commit

Permalink
Add alias String#dedup to String#-@ for Ruby v3.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
itarato committed May 18, 2023
1 parent 2beb695 commit be0e5c4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Compatibility:
* 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).
* Alias `String#-@` to `String#dedup` (@itarato).

Performance:

Expand Down
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: 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 be0e5c4

Please sign in to comment.