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

···

--
Posted via http://www.ruby-forum.com/.

Quoting Manas Dadarkar (lists@ruby-forum.com):

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

···

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

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

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 Dadarkar (lists@ruby-forum.com):

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

--
Posted via http://www.ruby-forum.com/\.

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.

···

On 11/19/2013 08:13 AM, Manas Dadarkar 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);