For example I have a variable jx.
How I can create an :jx symbol from it? (I can't find method)
···
--
Posted via http://www.ruby-forum.com/.
For example I have a variable jx.
How I can create an :jx symbol from it? (I can't find method)
--
Posted via http://www.ruby-forum.com/.
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 White
http://www.twitter.com/cwgem