Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > How to 'return' from a Proc?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 1st April 12:44
kero van gelder
External User
 
Posts: 1
Default How to 'return' from a Proc?



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.
  Reply With Quote


  sponsored links


2 1st April 12:45
martin demello
External User
 
Posts: 1
Default How to 'return' from a Proc?



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
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666