More specifically, the quotations are stripped if the following conditions are met (but the converse does not hold):
It starts with @, @@, $ or [,
the prefix is not followed by an identifier, and
it ends with =.
But the rule should only apply to :$= and :[]=, because (in my understanding) we should generally have eval(sym.inspect) == sym for the programmers' convenience.
First, inspect methods are not for eval.
We only guarantee that sym.name.to_sym == sym.
I understand it is not a guarantee and thus this is a relatively subtle issue. Nonetheless I think the behavior is not an intended one because Ruby values (including symbols) often implement #inspect in a way it is evaluatable.
Let me give more context on it: I was implementing the parser gem's AST serialization in another language to use the gem as a reference implementation. Under the hood it uses Symbol#inspect to stringify symbols and thus I was interested in the Symbol#inspect algorithm.
I realize that Ruby spends a considerable amount of effort to not print symbols in a format where they could not be roundtripped, and the discprancy between :"4_to_5" and :"4_to_5=" was surprising.
I bisected the change to the released versions of Ruby and found that the behaviour changed somewhere between ruby-2.2.0-preview1 and ruby-2.2.0-preview2:
@nobu (Nobuyoshi Nakada) I understand that Ruby does not guarantee that inspect methods are for eval but Ruby seems to consistently quote invalid Symbols in inspect, except for when they end with =. I think this is not consistent and Ruby might as well not quote Symbols in inspect at all, in this case. I think something has to change to keep consistency.