Class: Double::Klass

Inherits:
BasicObject
Extended by:
Forwardable
Defined in:
lib/double.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Klass

Returns a new instance of Klass.



16
17
18
# File 'lib/double.rb', line 16

def initialize(name)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mth, *args, &blk) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/double.rb', line 20

def method_missing(mth, *args, &blk)
  @klass ||= ::Kernel.eval "::#{@name}"
  if @klass.respond_to? mth
    (class << self; self; end).instance_eval do
      def_delegator :@klass, mth
    end
    @klass.send mth, *args, &blk
  else
    super
  end
end