I'm developing a C extension for ruby, one of the functions from the C library I'm accessing receives an options struct which seems to be naturally translate to an options hash in ruby-world.
The struct is being initialized with known default values when the hash on the ruby side does not define a value for a given option. On the C side I have some along these lines:
VALUE tmp;
tmp = rb_hash_aref(r_hash, rb_str_new2("opt1"));
if(TYPE(tmp) == T_STRING){
strcpy (c_learn_param->opt1, StringValuePtr(tmp));
}else{
strcpy (c_learn_param->opt1, "default value 1");
}
Now my problem is when an option has a defined value but the ruby type does not make sense in C.
Should I raise type error even for an optional value? that seems overkill, should I fall back to a default? the problem with falling back to a default is a user passing {"opt1" => 123 } will see the same behaviour as if he had not defined opt1 which seems like a bad idea, should I fall back and print a ruby warning? (do people even read them?).