1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* vm_eval.c: [DOC] [Bug #9551] Improve clarity of Kernel::catch

documentation, patch by Jesse Sielaff.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
zzak 2014-07-27 21:35:47 +00:00
parent 747243cc0e
commit 60272f90fd
2 changed files with 48 additions and 26 deletions

View file

@ -1,3 +1,8 @@
Mon Jul 28 06:34:43 2014 Zachary Scott <e@zzak.io>
* vm_eval.c: [DOC] [Bug #9551] Improve clarity of Kernel::catch
documentation, patch by Jesse Sielaff.
Mon Jul 28 06:24:54 2014 Zachary Scott <e@zzak.io> Mon Jul 28 06:24:54 2014 Zachary Scott <e@zzak.io>
* lib/uri/common.rb: [DOC] [Bug #9563] Recommend using URI.escape * lib/uri/common.rb: [DOC] [Bug #9563] Recommend using URI.escape

View file

@ -1780,39 +1780,56 @@ catch_i(VALUE tag, VALUE data)
/* /*
* call-seq: * call-seq:
* catch([arg]) {|tag| block } -> obj * catch([tag]) {|tag| block } -> obj
* *
* +catch+ executes its block. If a +throw+ is * +catch+ executes its block. If +throw+ is not called,
* executed, Ruby searches up its stack for a +catch+ block * the block executes normally, and +catch+ returns the
* with a tag corresponding to the +throw+'s * value of the last expression evaluated.
* _tag_. If found, that block is terminated, and
* +catch+ returns the value given to +throw+. If
* +throw+ is not called, the block terminates normally, and
* the value of +catch+ is the value of the last expression
* evaluated. +catch+ expressions may be nested, and the
* +throw+ call need not be in lexical scope.
* *
* def routine(n) * catch(1) { 123 } # => 123
* puts n *
* throw :done if n <= 0 * If +throw(tag2, val)+ is called, Ruby searches up its
* routine(n-1) * stack for a +catch+ block whose _tag_ has the same
* +object_id+ as _tag2_. If found, the block stops
* executing and returns _val_ (or +nil+ if no second
* argument was given to +throw+).
*
* catch(1) { throw(1, 456) } # => 456
* catch(1) { throw(1) } # => nil
*
* When _tag_ is passed as the first argument, +catch+
* yields it as the parameter of the block.
*
* catch(1) {|x| x + 2 } # => 3
*
* When no _tag_ is given, +catch+ yields a new unique
* object (as from +Object.new+) as the block parameter.
* This object can then be used as the argument to
* +throw+, and will match the correct +catch+ block.
*
* catch do |obj_A|
* catch do |obj_B|
* throw(obj_B, 123)
* puts "This puts is not reached"
* end * end
* *
* puts "This puts is displayed"
* 456
* end
* *
* catch(:done) { routine(3) } * # => 456
* *
* <em>produces:</em> * catch do |obj_A|
* catch do |obj_B|
* throw(obj_A, 123)
* puts "This puts is still not reached"
* end
* *
* 3 * puts "Now this puts is also not reached"
* 2 * 456
* 1 * end
* 0
*
* when _arg_ is given, +catch+ yields it as is, or when no
* _arg_ is given, +catch+ assigns a new unique object to
* +throw+. this is useful for nested +catch+. _arg_ can
* be an arbitrary object, not only Symbol.
* *
* # => 123
*/ */
static VALUE static VALUE