Instantiating Date class in Ruby C extension

Hi,

I want to instantiate the Date class in my Ruby C extension. However
when I pass arguments to the new method, I get an error that I am
passing arguments when zero arguments are expected. Note the following
syntax works via irb
requre ‘date’
myvar = Date.new(2013, 11,6)

However doing a rb_require(“date”) in the init method of my Ruby C
extension doesn’t help and I still get an error that I should not be
passing arguments to the new method. Can someone explain what I am doing
wrong?

-Manas

Subject: Instantiating Date class in Ruby C extension
Date: mar 19 nov 13 04:51:42 +0100

Quoting Manas D. ([email protected]):

However doing a rb_require(“date”) in the init method of my Ruby C
extension doesn’t help and I still get an error that I should not be
passing arguments to the new method.

You might want to post the C code…

Carlo

This is the C code
VALUE dateClass = rb_const_get(rb_cObject, rb_intern(“Date”));
VALUE dateArguments[3];
dateArguments[0] = INT2NUM(2013);
dateArguments[1] = INT2NUM(11);
dateArguments[2] = INT2NUM(6);
rubyColumnData = rb_funcall(dateClass, rb_intern(“new”), 3,
dateArguments);

Carlo E. Prelz wrote in post #1127920:

Subject: Instantiating Date class in Ruby C extension
Date: mar 19 nov 13 04:51:42 +0100

Quoting Manas D. ([email protected]):

However doing a rb_require(“date”) in the init method of my Ruby C
extension doesn’t help and I still get an error that I should not be
passing arguments to the new method.

You might want to post the C code…

Carlo

On 11/19/2013 08:13 AM, Manas D. wrote:

This is the C code
VALUE dateClass = rb_const_get(rb_cObject, rb_intern(“Date”));
VALUE dateArguments[3];
dateArguments[0] = INT2NUM(2013);
dateArguments[1] = INT2NUM(11);
dateArguments[2] = INT2NUM(6);
rubyColumnData = rb_funcall(dateClass, rb_intern(“new”), 3,
dateArguments);

Since dateArguments is VALUE*, you need to call rb_funcall2() instead of
rb_funcall().

Or you could call rb_funcall() and pass each of the three arguments
separately.

See README.EXT.