0

私の中に次のコード行がありますtest_func.rb

require 'inline'

class TestFunc
  inline do |builder|
    builder.c '
      int testfunc() {
        return 0;
      }'
  end
end

クラスではなく、オブジェクトからのみ関数を呼び出すことができます。

私はそれを次のように呼ぶことができます、

obj = TestFunc.new
obj.testfunc()

しかし、次のように呼び出すことができるように、どのように宣言すればよいですか?

TestFunc.testfunc()
4

1 に答える 1

2

Inline::C#c_singletonの代わりに使用Inline::C#c:

require 'inline'

class TestFunc
  inline do |builder|
    builder.c_singleton '
    int testfunc() {
      return 0;
    }'
  end

end

TestFunc.testfunc() # => 0

ドキュメントによると:

c_singleton : c と同じですが、クラス関数を追加します。

于 2013-11-07T11:47:45.970 に答える