Module: Tins::SexySingleton

Defined in:
lib/tins/sexy_singleton.rb

Defined Under Namespace

Modules: SingletonClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__old_singleton_included__Object



14
# File 'lib/tins/sexy_singleton.rb', line 14

alias __old_singleton_included__ included

Instance Method Details

#included(klass) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tins/sexy_singleton.rb', line 17

def included(klass)
  __old_singleton_included__(klass)
  (class << klass; self; end).class_eval do
    if Object.method_defined?(:respond_to_missing?)
      def  respond_to_missing?(name, *args)
        instance.respond_to?(name) || super
      end
    else
      def respond_to?(name, *args)
        instance.respond_to?(name) || super
      end
    end

    def method_missing(name, *args, &block)
      if instance.respond_to?(name)
        instance.__send__(name, *args, &block)
      else
        super
      end
    end
  end
  super
end