D
Daniel Berger
Hi all,
The various NUM2x functions (NUM2LONG, NUM2INT, etc) include builtin type
checks. However, they still seem to blindly accept symbols. Why?
/* foo.c */
#include "ruby.h"
#include <stdio.h>
static VALUE foo_test(VALUE self, VALUE num)
{
long x;
x = NUM2LONG(num);
printf("NUM: %ld\n", x);
return Qnil;
}
void Init_foo(){
VALUE cFoo = rb_define_class("Foo", rb_cObject);
rb_define_method(cFoo, "test", foo_test, 1);
}
# foo.rb
require "foo"
Foo.new.test("foo") # TypeError, expected
Foo.new.test("foo".to_sym) # NUM: 10201 - yikes!
Regards,
Dan
The various NUM2x functions (NUM2LONG, NUM2INT, etc) include builtin type
checks. However, they still seem to blindly accept symbols. Why?
/* foo.c */
#include "ruby.h"
#include <stdio.h>
static VALUE foo_test(VALUE self, VALUE num)
{
long x;
x = NUM2LONG(num);
printf("NUM: %ld\n", x);
return Qnil;
}
void Init_foo(){
VALUE cFoo = rb_define_class("Foo", rb_cObject);
rb_define_method(cFoo, "test", foo_test, 1);
}
# foo.rb
require "foo"
Foo.new.test("foo") # TypeError, expected
Foo.new.test("foo".to_sym) # NUM: 10201 - yikes!
Regards,
Dan