In order to create a BigDecimal from a C string in a Ruby extension, I'm doing this:
rb_funcall(rb_path2class("BigDecimal"), rb_intern("new"), 1, rb_str_new("0.0777", 6));
// => BigDecimal.new("0.0777")
Is there a shorter way to do this?
Also, stupid question, but is there an 'official' documentation for the C API (ruby 1.9.3), or does it just come down to reading the headers?
Unfortunately, the initialize
function, and pretty much the entire BigDecimal
C API, is declared as static and is thus not exposed.
The best way to learn about the C implementation of Ruby, and its API, is to browse the source, especially the ext
directory. There is also the README.EXT file, which describes the general API.