How to 'return' from a Proc?

  • Thread starter Kero van Gelder
  • Start date
K

Kero van Gelder

Hi!

I am trying to do

method() {
...
break if condition_met
...
}

to break out of the proc and thus finish the yield() in method()

But I can't find the proper control word for it.
break is illegal, so is return.

Either I'm blind, or it doesn't exist; please enlighten me.

Bye,
Kero.
 
M

Martin DeMello

Kero van Gelder said:
Hi!

I am trying to do

method() {
...
break if condition_met
...
}

to break out of the proc and thus finish the yield() in method()

I think 'next' is what you want - is this what you mean:

def x
(1..10).each {|i| yield i}
end

x {|i|
puts "before #{i}"
next if i == 5
puts "after #{i}"
}

martin
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top