Module: Stitcher::Core

Included in:
Module
Defined in:
lib/stitcher/core.rb

Instance Method Summary collapse

Instance Method Details

#stitcher_add(name, sig, method) ⇒ Object



21
22
23
24
# File 'lib/stitcher/core.rb', line 21

def stitcher_add name, sig, method
	sig = (method.arity < 0 ? +([Object] * method.arity.abs) : [Object] * method.arity.abs) unless sig
	stitcher_method_table(name)[sig] = method
end

#stitcher_method_detecting(name, *args, &block) ⇒ Object



26
27
28
29
30
# File 'lib/stitcher/core.rb', line 26

def stitcher_method_detecting name, *args, &block
	mtable = stitcher_method_table(name).to_a.reverse
	_, method = mtable.find {|sig, _| sig.=== args, &block }
	method
end

#stitcher_method_table(name) ⇒ Object



11
12
13
# File 'lib/stitcher/core.rb', line 11

def stitcher_method_table name
	instance_eval { @stitcher_method_table ||= {}; @stitcher_method_table[name] ||= {} }
end

#stitcher_method_table_all(name) ⇒ Object



15
16
17
18
19
# File 'lib/stitcher/core.rb', line 15

def stitcher_method_table_all name
	mtable = stitcher_method_table(name) unless superclass
	return stitcher_method_table_all(superclass, name).merge(mtable) if superclass
	mtable
end