# How do i stop a block being passed on?

**URL:** <https://www.ruby-forum.com/t/how-do-i-stop-a-block-being-passed-on/145621>\
**Category:** Ruby\
**Created:** [August 12, 2008, 8:19am UTC](https://www.ruby-forum.com/t/how-do-i-stop-a-block-being-passed-on/145621 "2008-08-12T08:19:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [August 12, 2008, 8:19am UTC](https://www.ruby-forum.com/t/how-do-i-stop-a-block-being-passed-on/145621/1 "2008-08-12T08:19:03Z")

</div>

Hello friends,

Im writing a ruby C API program, and i have this difficulty:

VALUE  
m\_func1(VALUE self) {  
m\_func2();  
}

the problem i have is that if a block is passed to m\_func1 it seems to  
also  
be passed onto m\_func2, how do i stop it being passed on? is there a way  
to  
‘delete’ a block after i’ve finished with it? (i.e yielded to it)

thx

john

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [August 12, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-a-block-being-passed-on/145621/2 "2008-08-12T23:25:52Z")

</div>

On Aug 12, 2008, at 12:16 AM, John M. wrote:

> the problem i have is that if a block is passed to m\_func1 it seems to  
> also  
> be passed onto m\_func2, how do i stop it being passed on? is there a  
> way  
> to  
> ‘delete’ a block after i’ve finished with it? (i.e yielded to it)

You need to create is a new ruby\_frame for m\_func2 to operate in. The  
frame contains all the information about what blocks are available,  
the scope, local variables, self, etc.

The only way to get a new ruby\_frame is to use rb\_funcall instead of  
directly calling m\_func2.

VALUE  
m\_func1(VALUE self) {  
rb\_funcall(self, rb\_intern(“func2”), 0);  
}

This code is going to be quite slower than just calling m\_func2  
directly. If performance is what you are after, I would recommend  
breaking out the core functionality of m\_func2 into an internal  
function (one that is not exposed to the ruby interpreter). m\_func1  
would call this internal function, and you would create a new m\_func2  
that handles a block and calls this same internal fucntion.

Blessings,  
TwP
