Project

General

Profile

Actions

Feature #12047

closed

Set#=== (aliased to include?)

Feature #12047: Set#=== (aliased to include?)

Added by Phrogz (Gavin Kistner) almost 10 years ago. Updated almost 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:73657]

Description

Add Set#=== as an alias for Set#include? so that sets may be used in case statements:

require 'set' GOOD_COMMANDS = Set[ :foo, :bar, :jim ] BAD_COMMANDS = Set[ :baz, :bax, :jam ] ODD_COMMANDS = Set[ :quux, :xyzzy ] case my_command when GOOD_COMMANDS then puts "Yay!" when BAD_COMMANDS then puts "Boo!" when ODD_COMMANDS then puts "Whaa?" end 

Updated by Phrogz (Gavin Kistner) almost 10 years ago Actions #1 [ruby-core:73658]

  • Subject changed from Set#=== to Set#=== (aliased to include?)

Updated by sawa (Tsuyoshi Sawada) almost 10 years ago Actions #2 [ruby-core:73660]

I think that is ad hoc. Splat could be used, just like with arrays.

case my_command when *GOOD_COMMANDS then puts "Yay!" when *BAD_COMMANDS then puts "Boo!" when *ODD_COMMANDS then puts "Whaa?" end 

And one-time splatting would be also more efficient than calling include? each time.

Updated by jonathanhefner (Jonathan Hefner) almost 6 years ago Actions #3 [ruby-core:97074]

This was added in Ruby 2.5, so I think this issue can be closed.

Updated by jeremyevans0 (Jeremy Evans) almost 6 years ago Actions #4

  • Status changed from Open to Closed
Actions

Also available in: PDF Atom