Feature #5893
closed
Added by neleai (Ondrej Bilka) almost 13 years ago.
Updated over 12 years ago.
Description
Hello. As returning from various blocks is recurring theme at list I propose following.
You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).
return,next,break,redo would work as they do now.
Here is example
while::loop true
10.times{|i|::outer
10.times{|j|::inter
next::outer if i>6
return::inner 42 if j>4
puts i,j
}
}::outer #For readability we could optionaly add label at end of block.
break::loop
end
On Fri, Jan 13, 2012 at 7:21 PM, Ondrej Bilka neleai@seznam.cz wrote:
Hello. As returning from various blocks is recurring theme at list I propose following.
You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).
Doesn't throw/catch to that already?
--
Anurag Priyam
On Fri, Jan 13, 2012 at 11:11:28PM +0900, Anurag Priyam wrote:
On Fri, Jan 13, 2012 at 7:21 PM, Ondrej Bilka neleai@seznam.cz wrote:
Hello. As returning from various blocks is recurring theme at list I propose following.
You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).
Doesn't throw/catch to that already?
No unless you are happy with passing result by global variable.
On Fri, Jan 13, 2012 at 11:34:17PM +0900, Yukihiro Matsumoto wrote:
Hi,
In message "Re: [ruby-core:42115] Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka neleai@seznam.cz writes:
|> Doesn't throw/catch to that already?
|No unless you are happy with passing result by global variable.
Have you ever tried? throw can pass the result to catch.
matz.
I did not know this one. In code I have seen it is typically
something like this.
def return_it(foo)
$foo=foo
throw(:my_constant)
end
$foo=nil
t=try(:my_constant){
yield
}
t=$foo if $foo
2012/1/13 Ondřej Bílka neleai@seznam.cz:
Yukihiro Matsumoto wrote:
throw can pass the result to catch.
I did not know this one.
In my opinion, Sinatra is a very good example here. Look for
throw/catch in lib/sinatra/base.rb
.
--
Anurag Priyam
Hi,
In message "Re: [ruby-core:42115] Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka neleai@seznam.cz writes:
|> Doesn't throw/catch to that already?
|No unless you are happy with passing result by global variable.
Have you ever tried? throw can pass the result to catch.
matz.
- Status changed from Open to Rejected
I believe this is already solved. Closing.
--
Yusuke Endoh mame@tsg.ne.jp
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0