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

Posted by Ricky N. (ricky_n)
on 2013-01-03 20:46
(Received via mailing list)
I have run into some code that widely uses symbols with the '@' sign.
Example: :@enable.

Is this considered legal syntax?
Posted by Bartosz DziewoƄski (matmarex)
on 2013-01-03 20:57
(Received via mailing list)
On Thu, 03 Jan 2013 20:45:44 +0100, Ricky Ng <dummey@gmail.com> 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.