Skip to content

Commit 9a11c98

Browse files
committed
Implement String#-@ and untag passing specs.
1 parent 79898d8 commit 9a11c98

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

spec/tags/core/string/uminus_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
fails:String#-@ returns the same object for equal unfrozen strings
2-
fails:String#-@ returns the same object when it's called on the same String literal
31
fails:String#-@ deduplicates frozen strings

src/main/ruby/core/string.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,8 @@ def +@
15901590
end
15911591

15921592
def -@
1593-
frozen? ? self : dup.freeze
1593+
str = frozen? ? self : dup.freeze
1594+
Truffle::StringOperations.intern_string(str)
15941595
end
15951596

15961597
def encoding

src/main/ruby/core/truffle/string_operations.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
module Truffle
1212
module StringOperations
1313

14+
FROZEN_STRING_HASH = {}
15+
16+
def self.intern_string(str)
17+
FROZEN_STRING_HASH[str] ||= str
18+
end
19+
1420
# Similar to MRI's Warning::buffer class
1521
class SimpleStringIO
1622
attr_reader :string

0 commit comments

Comments
 (0)