Module: PageEz::DelegatesTo

Defined in:
lib/page_ez/delegates_to.rb

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/page_ez/delegates_to.rb', line 3

def self.[](name)
  Module.new do
    define_singleton_method(:included) do |base|
      base.include(Module.new.tap do |mod|
        mod.class_eval %{
          def method_missing(*args, **kwargs, &block)
            if #{name}.respond_to?(args[0])
              #{name}.send(*args, **kwargs, &block)
            else
              super(*args, **kwargs, &block)
            end
          end

          def respond_to_missing?(method_name, include_private = false)
            #{name}.respond_to?(method_name, include_private) || super(method_name, include_private)
          end
        }, __FILE__, __LINE__ - 12
      end)
    end
  end
end