【问题标题】:How to use class in Ruby extension written in C defined in other C file?如何在其他 C 文件中定义的用 C 编写的 Ruby 扩展中使用类?
【发布时间】:2020-12-20 23:22:46
【问题描述】:

我在 C 中为 Ruby 创建了一个扩展,我目前正在努力在我也在 C 中定义的类上调用构造函数。

在使用类之前调用​​类定义代码。 我正在尝试使用

VALUE rb_cConfidenceInterval = rb_const_get( rb_cObject, rb_intern( "ConfidenceInterval" ) );
VALUE interval = rb_funcall(
        rb_cConfidenceInterval, rb_intern( "new" ), 2,
        rb_float_new( lower_bound ),
        rb_float_new( upper_bound )
);

但在 uninitialized constant ConfidenceInterval 上运行测试时失败。 NormalDistribution::ConfidenceInterval 也没有帮助。

为了提供一些上下文,代码在github上可用

知道如何获得课程吗?

我试图找到类似require 的东西,但它似乎不是这样的东西。

【问题讨论】:

    标签: c ruby-c-extension


    【解决方案1】:
    VALUE rb_cConfidenceInterval = rb_path2class( "NormalDistribution::ConfidenceInterval" );
    

    基于examples

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 2012-02-07
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多