Issue #9867 has been updated by ukasz Strzebiczyk.


Sorry for the delay.
I don't think I am able in specifying it in needed level of detail: (. If that's up to me, the issue can be closed.

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

* Author: ukasz Strzebiczyk
* Status: Feedback
* Priority: Low
* Assignee: Yukihiro Matsumoto
* Category: syntax
* Target version: 
----------------------------------------
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 goodidea?



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