How to get a reference to a block (when no explicit block parameteris used?)

K

Kenneth McDonald

In a function, I can find out if a block was given using block_given?,
but there's no way I can find to get hold of that block if it's there--
I can only yield to it, so far as I can tell. I know there has to be a
method somewhere to do this, could some kind soul enlighten me?

Many thanks,
Ken
 
J

Jan Friedrich

Kenneth McDonald said:
In a function, I can find out if a block was given using block_given?,
but there's no way I can find to get hold of that block if it's there--
I can only yield to it, so far as I can tell. I know there has to be a
method somewhere to do this, could some kind soul enlighten me?

Many thanks,
Ken

def my_meth param, &block
p block
end

Regards,
Jan Friedrich
 
K

Kenneth McDonald

Unfortunately, that produces a method that _requires_ a block--I want
one where the block is optional. But thanks for the feedback.

Ken
 
J

James Coglan

[Note: parts of this message were removed to make it a legal post.]

2008/11/26 Jan Friedrich said:
def my_meth param, &block
p block
end



The way I understood the question was as follows:

def my_method(arg)
if block_given?
yield(arg)
end
end

How to get a reference to the given block in this situation? This is
especially true if you use define_method, which cannot specify a block param
(at least not in 1.8). Any suggestions?
 
S

Sebastian Hungerecker

Kenneth said:
Unfortunately, that produces a method that _requires_ a block

No, it does not.

HTH,
Sebastian Hungerecker
=2D-=20
NP: Die =C4rzte - Mondo Bondage
Jabber: (e-mail address removed)
ICQ: 205544826
 
Y

Yossef Mendelssohn

Unfortunately, that produces a method that _requires_ a block--I want
one where the block is optional. But thanks for the feedback.

Did you try it?
nil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top