clarify README.EXT regarding symbols

J

Joel VanderWerf

I'd like to propose a clarification for README.EXT, after forgotting
(again) that symbols can be represented as ID and as VALUEs. What I
forgot was that you have to use ID2SYM to convert ID -> VALUE.
README.EXT doesn't mention this.

The original text is quoted below, followed by my proposed addition
(maybe it would be better in different part of the file, possibly
section 1.4):
2.2.2 ID or Symbol

You can invoke methods directly, without parsing the string. First I
need to explain about symbols (whose data type is ID). ID is the
integer number to represent Ruby's identifiers such as variable names.
It can be accessed from Ruby in the form:

:Identifier

You can get the symbol value from a string within C code by using

rb_intern(const char *name)

The ID of a symbol is not the same as the ruby VALUE that represents the
symbol as an object. If you want this VALUE, use the ID2SYM macro:

ID id_sym = rb_intern("a_symbol");
VALUE val_sym = ID2SYM(id);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top