Вопрос

I'm writing a Ruby 1.9 C extension and I want to do the following in ruby:

notifier = Notifier.new
notifier.on 'click' do
  puts "clicked!"
end

Now the problem with this is that on the C method, I only "receive" a block, and, as far as I know, it's not even a parameter: I just can call with with rb_yield.

So my question is: is there a way on a Ruby 1.9 C extension, to transform a block into a proc or something, so I can store it inside my module, and call it later whenever I want/need them? Like an async callback!

I already implemented this with Procs/lambdas, but it's just ugly not to use the block syntax directly.

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top