Sha256: 155585827dea14497fdc2b396a4ee44a20891487201468fd9484fe0430d3dfbe

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

module Festoon
  class Dynamic
    def initialize(thing)
      @thing = thing
    end

    def method_missing(method_id, *args, &block)
      intercept_return_self(thing.public_send(method_id, *args, &block))
    end

    def __decompose__
      if thing.respond_to?(:__decompose__)
        [self, *thing.__decompose__]
      else
        [self, thing]
      end
    end

    def ==(other)
      if other.is_a?(self.class)
        other == thing
      else
        thing == other
      end
    end

    private

    def thing
      @thing
    end

    def intercept_return_self(value)
      value == thing ? self : value
    end

    def respond_to_missing?(method_id, *args)
      thing.respond_to?(method_id)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
festoon-0.0.1 lib/festoon/dynamic.rb