Forum: Ruby Passing a proc as block to a method from a C extension

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
18ca239ffade6df0b839d26062f173fb?d=identicon&s=25 Dominik Bathon (Guest)
on 2006-02-18 19:57
(Received via mailing list)
Hi,

I am looking for a way to do the equivalent of the following ruby
function
in a C extension:

def foo(my_proc)
     bar(&my_proc)
end

(and it should also work if bar is instance_eval or module_eval)

I couldn't find a way to do this, the only idea I have is to do
something
like:

def foo(my_proc)
     bar { |arg| my_proc.call(arg) }
end

This can be done using rb_iterate, but it obviously doesn't work with
instance_eval and module_eval.

Any ideas?

Dominik
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-02-20 01:03
(Received via mailing list)
HI,

In message "Re: Passing a proc as block to a method from a C extension"
    on Sun, 19 Feb 2006 03:56:52 +0900, "Dominik Bathon" <dbatml@gmx.de>
writes:

|I am looking for a way to do the equivalent of the following ruby function
|in a C extension:
|
|def foo(my_proc)
|     bar(&my_proc)
|end
|
|(and it should also work if bar is instance_eval or module_eval)

Currently there's no good way, since no one has complained loudly
before.  Let me think about your request.

							matz.
18ca239ffade6df0b839d26062f173fb?d=identicon&s=25 Dominik Bathon (Guest)
on 2006-02-20 01:49
(Received via mailing list)
On Mon, 20 Feb 2006 01:01:28 +0100, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote:

> |def foo(my_proc)
> |     bar(&my_proc)
> |end
> |
> |(and it should also work if bar is instance_eval or module_eval)
>
> Currently there's no good way, since no one has complained loudly
> before.  Let me think about your request.

Ok, thanks. That's what I thought.

I would like to have a function like

VALUE rb_iterate_proc(VALUE (*it_proc)(), VALUE data1, VALUE proc);

that would work like block_pass().

Btw. could we also get a version of rb_iter_break that breaks with a
value
instead of just nil?


Dominik
This topic is locked and can not be replied to.