From: mortee Date: 2007-11-06T21:50:38+09:00 Subject: Re: string to symbol Fernando Cacciola wrote: > Hi people, > > Is there a way to "intern" a string so that it becomes denoted by a symbol? > > Something like: > > # This doesn't work as I wrote it, I know > :repetitive_message <= "blah blah blah" > > puts :repetitive_message > puts :repetitive_message > puts :repetitive_message > puts :repetitive_message If you use puts :"blah blah blah" then no matter how many times you write it, the symbol literal will reference the same symbol (as long as the literal is the same, of course). Also, you can assign either a simple string, or a symbol to a variable, thus reusing it without repeating in the source. my_str = "some string" my_sym = :"some symbol" puts my_str puts my_sym mortee