I'm trying to do something like this but I'm having trouble understanding how to use Ruby internals in my C code.
static VALUE func_get_date_object(VALUE self, VALUE vdate){
VALUE rb_date;
VALUE date;
rb_date = rb_funcall(rb_intern("Date"), rb_intern("new"), 0);;
date = rb_funcall(rb_date, rb_intern("parse"), 0);
return date;
}
What I want to do is pass in the vdate as a string like you would for Date.parse('yyyy-mm-dd')
But first I think that I need to know how to create or instantiate a new Date class object in C for Ruby. How may I do this please?
I have a test written for that code that does this.
def test_date
assert_equal('', @t.date(@t_date_str))
end
Output is
NoMethodError: undefined method `new' for 18709:Fixnum
rb_internreturns the internalIDfor the name "Date". What you want is the actual class associated with this name, and you can get that withrb_const_get:You can then use this with
rb_funcallto create a new instance of theDateclass:Since it looks like you actually want to call the
Date.parseclass method, what you probably want to do is callparsedirectly on the class: