Class: Module

Inherits:
Object show all
Defined in:
lib/core_ext/module.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



2
3
4
5
# File 'lib/core_ext/module.rb', line 2

def method_missing(method_name, *args, &block)
  @arg_sets ||= {}
  @arg_sets[method_name] = [args, block]
end

Instance Method Details

#included(klass) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/core_ext/module.rb', line 9

def included(klass)
  return unless defined? @arg_sets
  @arg_sets.each do |method, (args, block)|
    if klass.methods.include?(method.id2name)
      klass.send(method, *args, &block)
    else
      raise "method #{method} not defined in #{klass}"
    end
  end
end

#tartan_includedObject



7
# File 'lib/core_ext/module.rb', line 7

alias :tartan_included :included