I have run into some code that widely uses symbols with the '@' sign. Example: :@enable. Is this considered legal syntax?
on 2013-01-03 20:46
on 2013-01-03 20:57
On Thu, 03 Jan 2013 20:45:44 +0100, Ricky Ng <firstname.lastname@example.org> wrote: > I have run into some code that widely uses symbols with the '@' sign. > Example: :@enable. > > Is this considered legal syntax? Yes, :@enable creates a symbol for "@enable". This is the same as "@enable".to_sym, valid, and useful if you need to access instance variables of a class using instance_variable_get, as it takes a symbol argument. I think the syntax is allowed specifically for this case, similarly to how you can have constructs like :== or :<=> for appropriate symbols, to be used in other contexts as method names.