Having written the C extension for the Ruby gem, I need to check the parameter value for equality with a known character and string.
I understand you can put a string with
char *foo = "foo";
VALUE foo_string_value = rb_intern(foo);
and then convert it to a symbol:
VALUE foo_sym_value = ID2SYM(foo_string_value);
My question is whether I can now reliably check a parameter, which can be a character or a string, :fooor 'foo', moreover, they use C pointer equality:
if (param == foo_string_value || param == foo_sym_value) {
...
}
In other words, does interning guarantee that equality of the pointer is also equal to equality of values for characters and strings?
If this is the wrong approach, then what is the right choice for this comparison?
source
share