Sha256: 5020c0577ef69890b4fe43f8ae40afc92e41ae96c527987353e3290278486ce3

Contents?: true

Size: 550 Bytes

Versions: 1

Compression:

Stored size: 550 Bytes

Contents

module DuckPuncher
  module Decoration
    def decorators
      @decorators ||= ancestral_hash
    end

    def new_decorator(*ducks)
      targets = ducks.sort.map(&:target)
      decorator_class = DelegateClass(targets.first)
      DuckPuncher.redefine_constant "#{targets.first.to_s.tr(':', '')}Delegator", decorator_class
      ducks.each { |duck| duck.punch target: decorator_class, method: :prepend }
      decorator_class
    end

    def undecorate(obj)
      obj = obj.__getobj__ while obj.respond_to? :__getobj__
      obj
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duck_puncher-4.0.0 lib/duck_puncher/decoration.rb