Project

General

Profile

Actions

Feature #12076

closed

The 'ditto' operator

Added by joelbryan (Joel Bryan Juliano) about 8 years ago. Updated about 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:73825]

Description

I like to introduce and propose an idea to use a 'ditto' operator in 'else' or 'elsif' statement,
the ditto operator is a reference to the true statement in the if conditions to be used in the proceeding else and elsif statements,
the goal is to reuse the true statement for other conditions also it will make the code to be much readable than recopying and pasting the true statement again.

if user == "foo"
  puts "welcome" + user  # => welcome foo
elsif user == "bar"
  ditto # => welcome bar
else
  user = "stranger"
  ditto # => welcome stranger
end

Updated by joelbryan (Joel Bryan Juliano) about 8 years ago

  • Description updated (diff)

Updated by sawa (Tsuyoshi Sawada) about 8 years ago

The example code can be refactored to:

case user
when "foo", "bar"
else user = "stranger"
end
puts "welcome" + user

Updated by matz (Yukihiro Matsumoto) about 8 years ago

  • Status changed from Open to Rejected

Rejected. Adding new keyword is not a good idea, besides ditto behavior is not clear.

Matz.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0