首页 > 解决方案 > 使用 ruby​​inline 时如何调用同一模块中的方法?

问题描述

我正在使用 ruby​​inline。

在其中,我定义了两个函数,“splitter”和“sample_replace”。

我想要做的是从拆分器调用 sample_replace 而不通过 Ruby,但我无法让它工作。

有没有办法调用它?

require "inline"
module Sample
  inline(:C) do |builder|
    builder.c_singleton <<-EOS
      static VALUE spliter( VALUE str){
        VALUE *cap_list = rb_str_split(str,"");

        // I want to call "sample_replace" methods.

        return cap_list;
      }
    EOS
  end

  inline(:C) do |builder|
    builder.c_singleton <<-EOS
      static VALUE sample_replace( VALUE str){
         if(strcmp(one_str,"5")==0){
           return rb_str_new2("1");
        }
        return rb_str_new2(str);
      }
    EOS
  end
end

标签: crubyclang

解决方案


推荐阅读