[ruby-core:62797] [ruby-trunk - Feature #9867] [Feedback] Introduce each/else block into ruby

From: nobu@...
Date: 2014-05-27 14:14:38 UTC
List: ruby-core #62797
Issue #9867 has been updated by Nobuyoshi Nakada.

Status changed from Open to Feedback

How would you define `else` block for other than `Array#each`?

----------------------------------------
Feature #9867: Introduce each/else block into ruby
https://bugs.ruby-lang.org/issues/9867#change-46911

* Author: =C5=81ukasz Strzebi=C5=84czyk
* Status: Feedback
* Priority: Low
* Assignee: Yukihiro Matsumoto
* Category: syntax
* Target version:=20
----------------------------------------
Hi

Code like this happens quite often:

    if array.any?
      array.each do |elem|
        some_work
      end
    else
      do_something_else
    end

I was thinking if it was possible, to introduce syntax like this:

    array.each do |elem|
      some_work
    else
      do_something_else
    end

where code in else would fire if array is empty. This would simplify a lot =
of code nicely and would be completely backwards compatible. Is that a good=
 idea?



--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next