This is a reprint of Blog Article.
RubyKaigi Takeout 2020 Thank you for your hard work. This time I participated for the first time because it was online, but it was fun to talk about interesting content. In particular, the introduction of sandals from sawanobori and the daily delivery of committers who cook rice and bake fish on a bonfire felt new normal. No, when it comes to Ruby committers, you need technology to develop in a harsh environment-it will be a learning experience! Oh, and Refinements is a great feature, so let's use it more and more and become a new normal.
By the way, RubyKaigi fever hasn't cooled down yet, but this time it was exciting at Ruby Committers vs the World on the first day Symbol # I briefly summarized the story of to_s
.
Symbol # to_s
Just around this time last year, a proposal was made to make the string returned by # to_s`` frozen
.
With this ticket, the main subject "Let's make the return value frozen of Symbol # to_s
"came out.
This ticket also contains a modification that returns a frozen String for the following methods as well as Symbol # to_s
.
Module#name
TrueClass/FalseClass#to_s
NilClass#to_s
Please refer to the following links for related PR and background.
This change was approved by Mr. Matsumoto and was pre-released as an "experimental feature" in Ruby 2.7 preview2 after the merge.
Symbol # to_s
I'm glad that Symbol # to_s
now returns a frozen String for better performance.
So I wish I had done it, but after merging the changes in Symbol # to_s
, I found that there was a problem with one of the gems.
For example, in pry
, the code that changes the return value of Symbol # to_s
destructively was written as follows, which had an effect.
def method_missing(method, *args, &block)
meth = method.to_s
if meth.end_with?('?')
# to_Since the return value of s is changed destructively, an error will occur if it is a frozen String ...
meth.chop!
present?(meth) || present?(meth.tr('_', '-'))
else
super
end
end
Some code that has changed the return value of Symbol # to_s
destructively like this has been reported, and Ruby 2.7 also has support around keyword arguments, so to avoid confusion, Symbol # in Ruby 2.7 Correspondence of to_s
has been postponed.
Also, the only change that was reverted was the change to Symbol # to_s
, and the following method was changed to return a frozen String and was released as a feature of Ruby 2.7.
Module#name
TrueClass/FalseClass#to_s
NilClass#to_s
An extension of Ruby Committers vs the World of RubyKaigi Takeout 2020 held last month. There was just a discussion of Symbol # to_s
.
There was a lot of discussion about what to do with Symbol # to_s
, but one conclusion was that instead of making Symbol # to_s
incompatible, we added a method with an alias of Symbol # name
. I did.
And on that day, Symbol # name
was merged into the development version. There is momentum.
Symbol # to_s
and Module # name
NilClass # to_s
and TrueClass # to_s
FalseClass # to_s
〜〜〜Symbol # name
that returns a frozen String
HashWithIndifferentAccess
throws a PR that calls Symbol # name
〜〜〜So, I briefly summarized the Symbol # to_s
problem.
Looking only at the results, it was incompatible with a large range of influence, but it is difficult to some extent because there are problems that you do not understand until you actually release it.
Rather, in this case, it turned out that there was a problem with the pre-release version, so it can be said that it was working correctly as a pre-release.
I'm glad I knew it before it became a problem in the official version.
When the Ruby 3.0 preview version comes out, everyone should try it out and see if there are any problems.