Sha256: 35581f36d8dda9c6728c0c27269a86228f173327a6b7046bcf1d79a612a17c70

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

class DumbDelegator < ::BasicObject
  ##
  # 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.
  #
  # @example Extending a Class/Module to handle class equality for a DumbDelegator instance.
  #
  # target = MyAwesomeClass.new
  # dummy = DumbDelegator.new(target)
  #
  # MyAwesomeClass === dummy #=> false
  # DumbDelegator === dummy  #=> true
  #
  # MyAwesomeClass.extend(DumbDelegator::TripleEqualExt)
  #
  # MyAwesomeClass === dummy #=> true
  # DumbDelegator === dummy  #=> true
  module TripleEqualExt
    # Case equality for the extended Class/Module and then given +other+.
    #
    # @param other [Object] An instance of any Object
    #
    # @return [Boolean] If the +other+ is an instance of the Class/Module.
    def ===(other)
      super || other.is_a?(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dumb_delegator-1.0.0 lib/dumb_delegator/triple_equal_ext.rb