Class: Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/enumbler/core_ext/symbol/case_equality_operator.rb

Overview

Use case equality operator with an enabled class.

case House.black
when :black
'this is true'
when :blue, :purple
'this is not'
end

Instance Method Summary collapse

Instance Method Details

#===(other) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/enumbler/core_ext/symbol/case_equality_operator.rb', line 12

def ===(other)
  super ||
    (other.class.included_modules.include?(Enumbler::Enabler) &&
      other.enumble.enum == self)

# Calling #enumble on a new instance that has not been defined raises an
# error, so catching that edge case here
rescue Enumbler::Error
  false
end