Project

General

Profile

Actions

Feature #9867

closed

Introduce each/else block into ruby

Added by Killa (Łukasz Strzebińczyk) almost 10 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
[ruby-core:62796]

Description

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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0