I am trying to find a way to test symbol equality in the Ruby C API. Consider the following C function:
static VALUE test_symbol_equality(VALUE self, VALUE symbol) {
if (rb_intern("test") == symbol) {
return Qtrue;
} else {
return Qfalse;
}
}
From the Ruby point of view, this method does not behave as expected:
test_symbol_equality(:test) # => false
Why is this the case? How do I need to change the code to achieve the expected behaviour?
You are not comparing the same thing in your example.
rb_internreturns anID, but you are comparing it to theVALUEdirectly. You first have to “unwrap” theVALUE, retrieving theIDit is associated with. Replacing yourifstatement by this should solve your problem: