When exactly don't you have to :"escape"
a Ruby symbol?
Because this question is somehow related to the Ruby interpreter's internal usage of symbols, the rules are not the most obvious ones:
:
+ Identifier¹, optionally appended by!
,?
, or=
(→ methods):@
+ Identifier¹ (→ instance variables):@@
+ Identifier¹ (→ class variables):$
+ Identifier¹ (→ global variables):$
+ Single identifier¹ character or0-9
(→ Perl-style special variables):$-
+ Single identifier¹ character or0-9
(→ Ruby interpreter CLI options):!
,:!=
,:!~
,:%
,:&
,:*
,:+
,:-
,:/
,:<
,:>
,:^
,:`
,:|
,:~
,:$!
,:$"
,:$$
,:$&
,:$'
,:$*
,:$+
,:$,
,:$.
,:$/
,:$:
,:$;
,:$<
,:$=
,:$>
,:$?
,:$@
,:$\
,:$`
,:$~
,:**
,:+@
,:-@
,:<<
,:<=
²,:<=>
²,:==
,:===
,:=~
,:>=
,:>>
,:[]
,:[]=
¹ Valid for identifiers: A-Z
, a-z
, 0-9
, _
, non-ASCII characters. Not allowed to start with 0-9
.
² Example of a syntactical edge case that is not 100% clear
More Idiosyncratic Ruby
- Please Comment on GitHub
- Next Article: Proper Unicoding
- Previous Article: Fixed Numbers