Symbol from variable name

For example I have a variable jx.

How I can create an :jx symbol from it? (I can’t find method)

For example I have a variable jx.

How I can create an :jx symbol from it? (I can’t find method)

This seems like a bid of an odd use case. Can you give more detailed
code to show what you’re trying to accomplish? As is you’ve already
answered your own question which is that you can get a symbol from a
name by prefixing it with a colon. No methods involved, just syntax.

If you’re instead referring to the value of a variable, then you can use
to_sym if it’s supported by the object in question (strings for
example), or simply convert the object to a string somehow.

Regards,
Chris W.
http://www.twitter.com/cwgem

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