jbk jbk - 30 days ago 7
Ruby Question

Symbols with various characters

I would like to turn strings like the following into symbols:


  • 'Architects & Engineers'

  • 'Catering & Hotels'



They have characters like
'&'
,
'/'
.

How can I achieve this?

Answer Source
'Architects & Engineers'.to_sym == :'Architects & Engineers'
#⇒ true

['Architects & Engineers'.to_sym, :'Architects & Engineers'].map(&:to_s)
#⇒ ["Architects & Engineers", "Architects & Engineers"]