Skip to content

Commit ec4ca91

Browse files
authored
Small documentation adjustments for new/updated features (#15634)
* Document Range#to_set * Update Thread#raise and Fiber#raise signatures and docs * Add reference to String#strip to character_selectors.rdoc * Update *nil docs when calling methods * Enhance Array#find and #rfind docs * Add a notice to Kernel#raise about cause:
1 parent 77c3a9e commit ec4ca91

File tree

7 files changed

+53
-29
lines changed

7 files changed

+53
-29
lines changed

array.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,7 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
21022102
*
21032103
* If no such element is found, calls +if_none_proc+ and returns its return value.
21042104
*
2105-
* [1, 3, 5].find(proc {false}) {|element| element > 12} # => false
2106-
* [[:foo, 0], [:bar, 1], [:baz, 2]].find {|key, value| key.start_with?('b') } # => [:bar, 1]
2107-
* [[:foo, 0], [:bar, 1], [:baz, 2]].find(proc {[]}) {|key, value| key.start_with?('c') } # => []
2105+
* [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
21082106
*
21092107
* With no block given, returns an Enumerator.
21102108
*
@@ -2140,16 +2138,14 @@ rb_ary_find(int argc, VALUE *argv, VALUE ary)
21402138
* Returns the last element for which the block returns a truthy value.
21412139
*
21422140
* With a block given, calls the block with successive elements of the array in
2143-
* reverse order; returns the last element for which the block returns a truthy
2141+
* reverse order; returns the first element for which the block returns a truthy
21442142
* value:
21452143
*
2146-
* (0..9).rfind {|element| element < 5} # => 4
2144+
* [1, 2, 3, 4, 5, 6].rfind {|element| element < 5} # => 4
21472145
*
21482146
* If no such element is found, calls +if_none_proc+ and returns its return value.
21492147
*
2150-
* (0..9).rfind(proc {false}) {|element| element < -2} # => false
2151-
* {foo: 0, bar: 1, baz: 2}.rfind {|key, value| key.start_with?('b') } # => [:baz, 2]
2152-
* {foo: 0, bar: 1, baz: 2}.rfind(proc {[]}) {|key, value| key.start_with?('c') } # => []
2148+
* [1, 2, 3, 4].rfind(proc {0}) {|element| element < -2} # => 0
21532149
*
21542150
* With no block given, returns an Enumerator.
21552151
*

cont.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,28 +3246,37 @@ rb_fiber_raise(VALUE fiber, int argc, VALUE *argv)
32463246

32473247
/*
32483248
* call-seq:
3249-
* fiber.raise -> obj
3250-
* fiber.raise(string) -> obj
3251-
* fiber.raise(exception [, string [, array]]) -> obj
3249+
* raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
3250+
* raise(message = nil, cause: $!)
32523251
*
32533252
* Raises an exception in the fiber at the point at which the last
3254-
* +Fiber.yield+ was called. If the fiber has not been started or has
3253+
* +Fiber.yield+ was called.
3254+
*
3255+
* f = Fiber.new {
3256+
* puts "Before the yield"
3257+
* Fiber.yield 1 # -- exception will be raised here
3258+
* puts "After the yield"
3259+
* }
3260+
*
3261+
* p f.resume
3262+
* f.raise "Gotcha"
3263+
*
3264+
* Output
3265+
*
3266+
* Before the first yield
3267+
* 1
3268+
* t.rb:8:in 'Fiber.yield': Gotcha (RuntimeError)
3269+
* from t.rb:8:in 'block in <main>'
3270+
*
3271+
* If the fiber has not been started or has
32553272
* already run to completion, raises +FiberError+. If the fiber is
32563273
* yielding, it is resumed. If it is transferring, it is transferred into.
32573274
* But if it is resuming, raises +FiberError+.
32583275
*
3259-
* With no arguments, raises a +RuntimeError+. With a single +String+
3260-
* argument, raises a +RuntimeError+ with the string as a message. Otherwise,
3261-
* the first parameter should be the name of an +Exception+ class (or an
3262-
* object that returns an +Exception+ object when sent an +exception+
3263-
* message). The optional second parameter sets the message associated with
3264-
* the exception, and the third parameter is an array of callback information.
3265-
* Exceptions are caught by the +rescue+ clause of <code>begin...end</code>
3266-
* blocks.
3267-
*
32683276
* Raises +FiberError+ if called on a Fiber belonging to another +Thread+.
32693277
*
3270-
* See Kernel#raise for more information.
3278+
* See Kernel#raise for more information on arguments.
3279+
*
32713280
*/
32723281
static VALUE
32733282
rb_fiber_m_raise(int argc, VALUE *argv, VALUE self)

doc/language/character_selectors.rdoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Each of these instance methods accepts one or more character selectors:
1414
- String#delete!(*selectors): returns +self+ or +nil+.
1515
- String#squeeze(*selectors): returns a new string.
1616
- String#squeeze!(*selectors): returns +self+ or +nil+.
17+
- String#strip(*selectors): returns a new string.
18+
- String#strip!(*selectors): returns +self+ or +nil+.
1719

1820
A character selector identifies zero or more characters in +self+
1921
that are to be operands for the method.
@@ -79,6 +81,8 @@ These instance methods accept multiple character selectors:
7981
- String#delete!(*selectors): returns +self+ or +nil+.
8082
- String#squeeze(*selectors): returns a new string.
8183
- String#squeeze!(*selectors): returns +self+ or +nil+.
84+
- String#strip(*selectors): returns a new string.
85+
- String#strip!(*selectors): returns +self+ or +nil+.
8286

8387
In effect, the given selectors are formed into a single selector
8488
consisting of only those characters common to _all_ of the given selectors.

doc/syntax/calling_methods.rdoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ as one argument:
355355
# Prints the object itself:
356356
# #<Name:0x00007f9d07bca650 @name="Jane Doe">
357357

358-
This allows to handle one or many arguments polymorphically. Note also that +nil+
359-
has NilClass#to_a defined to return an empty array, so conditional unpacking is
360-
possible:
358+
This allows to handle one or many arguments polymorphically. Note also that <tt>*nil</tt>
359+
is unpacked to an empty list of arguments, so conditional unpacking is possible:
361360

362361
my_method(*(some_arguments if some_condition?))
363362

eval.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ rb_f_raise(int argc, VALUE *argv)
922922
* With argument +exception+ not given,
923923
* argument +message+ and keyword argument +cause+ may be given,
924924
* but argument +backtrace+ may not be given.
925+
*
926+
* +cause+ can not be given as an only argument.
927+
*
925928
*/
926929

927930
static VALUE

range.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,20 @@ range_to_a(VALUE range)
10181018
return rb_call_super(0, 0);
10191019
}
10201020

1021+
/*
1022+
* call-seq:
1023+
* to_set -> set
1024+
*
1025+
* Returns a set containing the elements in +self+, if a finite collection;
1026+
* raises an exception otherwise.
1027+
*
1028+
* (1..4).to_set # => Set[1, 2, 3, 4]
1029+
* (1...4).to_set # => Set[1, 2, 3]
1030+
*
1031+
* (1..).to_set
1032+
* # in 'Range#to_set': cannot convert endless range to a set (RangeError)
1033+
*
1034+
*/
10211035
static VALUE
10221036
range_to_set(int argc, VALUE *argv, VALUE range)
10231037
{

thread.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,12 +2908,11 @@ rb_thread_fd_close(int fd)
29082908

29092909
/*
29102910
* call-seq:
2911-
* thr.raise
2912-
* thr.raise(string)
2913-
* thr.raise(exception [, string [, array]])
2911+
* raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
2912+
* raise(message = nil, cause: $!)
29142913
*
29152914
* Raises an exception from the given thread. The caller does not have to be
2916-
* +thr+. See Kernel#raise for more information.
2915+
* +thr+. See Kernel#raise for more information on arguments.
29172916
*
29182917
* Thread.abort_on_exception = true
29192918
* a = Thread.new { sleep(200) }

0 commit comments

Comments
 (0)