Sha256: 16cba1ba460a029770cb28aa64119a486a3ad55a473c8138c523f688f858927a

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

# Based on http://git.io/D7oevQ
require 'forwardable'

unless defined? BasicObject
  class BasicObject
    instance_methods.each do |mth|
      undef_method mth unless mth =~ /__/
    end
  end
end

module Double
  class Klass < BasicObject
    extend ::Forwardable

    def initialize(name)
      @name = name
    end

    def _
      @_ ||= ::Kernel.const_get @name
    end

    def method_missing(mth, *args, &blk)
      if _.respond_to? mth
        (class << self; self; end).instance_eval do
          def_delegator :@_, mth
        end
        @_.send mth, *args, &blk
      else
        super
      end
    end
  end

  def const_missing(name)
    Klass.new name
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
double-0.1.0 lib/double.rb