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_intern
returns the internalID
for 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_funcall
to create a new instance of theDate
class:Since it looks like you actually want to call the
Date.parse
class method, what you probably want to do is callparse
directly on the class: