:@fudgeKittens, the use of ':' with '@'

I have run into some code that widely uses symbols with the ‘@’ sign.
Example: :@enable.

Is this considered legal syntax?

On Thu, 03 Jan 2013 20:45:44 +0100, Ricky Ng removed_[email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs