diff --git a/array.c b/array.c index 27b84249bf..e13239ad3d 100644 --- a/array.c +++ b/array.c @@ -2102,9 +2102,7 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary) * * If no such element is found, calls +if_none_proc+ and returns its return value. * - * [1, 3, 5].find(proc {false}) {|element| element > 12} # => false - * [[:foo, 0], [:bar, 1], [:baz, 2]].find {|key, value| key.start_with?('b') } # => [:bar, 1] - * [[:foo, 0], [:bar, 1], [:baz, 2]].find(proc {[]}) {|key, value| key.start_with?('c') } # => [] + * [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1 * * With no block given, returns an Enumerator. * @@ -2140,16 +2138,14 @@ rb_ary_find(int argc, VALUE *argv, VALUE ary) * Returns the last element for which the block returns a truthy value. * * With a block given, calls the block with successive elements of the array in - * reverse order; returns the last element for which the block returns a truthy + * reverse order; returns the first element for which the block returns a truthy * value: * - * (0..9).rfind {|element| element < 5} # => 4 + * [1, 2, 3, 4, 5, 6].rfind {|element| element < 5} # => 4 * * If no such element is found, calls +if_none_proc+ and returns its return value. * - * (0..9).rfind(proc {false}) {|element| element < -2} # => false - * {foo: 0, bar: 1, baz: 2}.rfind {|key, value| key.start_with?('b') } # => [:baz, 2] - * {foo: 0, bar: 1, baz: 2}.rfind(proc {[]}) {|key, value| key.start_with?('c') } # => [] + * [1, 2, 3, 4].rfind(proc {0}) {|element| element < -2} # => 0 * * With no block given, returns an Enumerator. * diff --git a/cont.c b/cont.c index 0087994730..b33c1462bf 100644 --- a/cont.c +++ b/cont.c @@ -3246,28 +3246,37 @@ rb_fiber_raise(VALUE fiber, int argc, VALUE *argv) /* * call-seq: - * fiber.raise -> obj - * fiber.raise(string) -> obj - * fiber.raise(exception [, string [, array]]) -> obj + * raise(exception, message = exception.to_s, backtrace = nil, cause: $!) + * raise(message = nil, cause: $!) * * Raises an exception in the fiber at the point at which the last - * +Fiber.yield+ was called. If the fiber has not been started or has + * +Fiber.yield+ was called. + * + * f = Fiber.new { + * puts "Before the yield" + * Fiber.yield 1 # -- exception will be raised here + * puts "After the yield" + * } + * + * p f.resume + * f.raise "Gotcha" + * + * Output + * + * Before the first yield + * 1 + * t.rb:8:in 'Fiber.yield': Gotcha (RuntimeError) + * from t.rb:8:in 'block in
' + * + * If the fiber has not been started or has * already run to completion, raises +FiberError+. If the fiber is * yielding, it is resumed. If it is transferring, it is transferred into. * But if it is resuming, raises +FiberError+. * - * With no arguments, raises a +RuntimeError+. With a single +String+ - * argument, raises a +RuntimeError+ with the string as a message. Otherwise, - * the first parameter should be the name of an +Exception+ class (or an - * object that returns an +Exception+ object when sent an +exception+ - * message). The optional second parameter sets the message associated with - * the exception, and the third parameter is an array of callback information. - * Exceptions are caught by the +rescue+ clause of begin...end - * blocks. - * * Raises +FiberError+ if called on a Fiber belonging to another +Thread+. * - * See Kernel#raise for more information. + * See Kernel#raise for more information on arguments. + * */ static VALUE rb_fiber_m_raise(int argc, VALUE *argv, VALUE self) diff --git a/doc/language/character_selectors.rdoc b/doc/language/character_selectors.rdoc index 47cf242be7..20685b8392 100644 --- a/doc/language/character_selectors.rdoc +++ b/doc/language/character_selectors.rdoc @@ -14,6 +14,8 @@ Each of these instance methods accepts one or more character selectors: - String#delete!(*selectors): returns +self+ or +nil+. - String#squeeze(*selectors): returns a new string. - String#squeeze!(*selectors): returns +self+ or +nil+. +- String#strip(*selectors): returns a new string. +- String#strip!(*selectors): returns +self+ or +nil+. A character selector identifies zero or more characters in +self+ that are to be operands for the method. @@ -79,6 +81,8 @@ These instance methods accept multiple character selectors: - String#delete!(*selectors): returns +self+ or +nil+. - String#squeeze(*selectors): returns a new string. - String#squeeze!(*selectors): returns +self+ or +nil+. +- String#strip(*selectors): returns a new string. +- String#strip!(*selectors): returns +self+ or +nil+. In effect, the given selectors are formed into a single selector consisting of only those characters common to _all_ of the given selectors. diff --git a/doc/syntax/calling_methods.rdoc b/doc/syntax/calling_methods.rdoc index bf5916e99a..76babcc3dc 100644 --- a/doc/syntax/calling_methods.rdoc +++ b/doc/syntax/calling_methods.rdoc @@ -355,9 +355,8 @@ as one argument: # Prints the object itself: # # -This allows to handle one or many arguments polymorphically. Note also that +nil+ -has NilClass#to_a defined to return an empty array, so conditional unpacking is -possible: +This allows to handle one or many arguments polymorphically. Note also that *nil +is unpacked to an empty list of arguments, so conditional unpacking is possible: my_method(*(some_arguments if some_condition?)) diff --git a/eval.c b/eval.c index 0c80872bee..deadd5dd64 100644 --- a/eval.c +++ b/eval.c @@ -922,6 +922,9 @@ rb_f_raise(int argc, VALUE *argv) * With argument +exception+ not given, * argument +message+ and keyword argument +cause+ may be given, * but argument +backtrace+ may not be given. + * + * +cause+ can not be given as an only argument. + * */ static VALUE diff --git a/range.c b/range.c index f82d1a316d..82c252e3ef 100644 --- a/range.c +++ b/range.c @@ -1018,6 +1018,20 @@ range_to_a(VALUE range) return rb_call_super(0, 0); } +/* + * call-seq: + * to_set -> set + * + * Returns a set containing the elements in +self+, if a finite collection; + * raises an exception otherwise. + * + * (1..4).to_set # => Set[1, 2, 3, 4] + * (1...4).to_set # => Set[1, 2, 3] + * + * (1..).to_set + * # in 'Range#to_set': cannot convert endless range to a set (RangeError) + * + */ static VALUE range_to_set(int argc, VALUE *argv, VALUE range) { diff --git a/thread.c b/thread.c index 788a0e9ad7..e66352c03f 100644 --- a/thread.c +++ b/thread.c @@ -2908,12 +2908,11 @@ rb_thread_fd_close(int fd) /* * call-seq: - * thr.raise - * thr.raise(string) - * thr.raise(exception [, string [, array]]) + * raise(exception, message = exception.to_s, backtrace = nil, cause: $!) + * raise(message = nil, cause: $!) * * Raises an exception from the given thread. The caller does not have to be - * +thr+. See Kernel#raise for more information. + * +thr+. See Kernel#raise for more information on arguments. * * Thread.abort_on_exception = true * a = Thread.new { sleep(200) }