Module: DumbDelegator::TripleEqualExt

Defined in:
lib/dumb_delegator/triple_equal_ext.rb

Overview

This optional extension enables a Class/Module to support case statements.

Specifically, it monkey-patches a Class/Module's :=== method to check if the other argument is an instance of the extended Class/Module.

target = MyAwesomeClass.new dummy = DumbDelegator.new(target)

MyAwesomeClass === dummy #=> false DumbDelegator === dummy #=> true

MyAwesomeClass.extend(DumbDelegator::TripleEqualExt)

MyAwesomeClass === dummy #=> true DumbDelegator === dummy #=> true

Examples:

Extending a Class/Module to handle class equality for a DumbDelegator instance.

Instance Method Summary collapse

Instance Method Details

#===(other) ⇒ Boolean

Case equality for the extended Class/Module and then given other.

Parameters:

  • other (Object)

    An instance of any Object

Returns:

  • (Boolean)

    If the other is an instance of the Class/Module.


25
26
27
# File 'lib/dumb_delegator/triple_equal_ext.rb', line 25

def ===(other)
  super || other.is_a?(self)
end