diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2019-09-26 17:27:47 +0200 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-27 13:52:33 +0900 |
commit | eff15a269fdc37d2b09cf1dfe8c1b1bf6e377a32 (patch) | |
tree | 893d0292f67673e2425727e2ecd398a89d7043c9 /spec/ruby/core/nil/to_s_spec.rb | |
parent | 2082a26dc75da7cb76150b51cd5b8f7636ad0fa2 (diff) | |
download | ruby-eff15a269fdc37d2b09cf1dfe8c1b1bf6e377a32.tar.gz |
[EXPERIMENTAL] Make NilClass#to_s, TrueClass#to_s and FalseClass#to_s return a frozen String
* Always the same frozen String for each of these values.
* Avoids extra allocations whenever calling these 3 methods.
* See [Feature #16150]
Diffstat (limited to 'spec/ruby/core/nil/to_s_spec.rb')
-rw-r--r-- | spec/ruby/core/nil/to_s_spec.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/ruby/core/nil/to_s_spec.rb b/spec/ruby/core/nil/to_s_spec.rb index c7a18e2527..4b61f589f7 100644 --- a/spec/ruby/core/nil/to_s_spec.rb +++ b/spec/ruby/core/nil/to_s_spec.rb @@ -4,4 +4,14 @@ describe "NilClass#to_s" do it "returns the string ''" do nil.to_s.should == "" end + + ruby_version_is "2.7" do + it "returns a frozen string" do + nil.to_s.frozen?.should == true + end + + it "always returns the same string" do + nil.to_s.should equal(nil.to_s) + end + end end |