Module: MethodRepository::ModuleMethods
- Defined in:
- lib/method_repository.rb
Instance Method Summary collapse
Instance Method Details
#extended(base) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/method_repository.rb', line 10 def extended(base) klass_name = base.class.to_s == 'Class' ? base.to_s : base.class.to_s if (methods = @targets[klass_name]) singleton_class = class << base; self; end singleton_class.class_eval do methods.each do |method| define_method method[:name], method[:block] end end end end |
#included(base) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/method_repository.rb', line 23 def included(base) if (methods = @targets[base.to_s]) base.class_eval do methods.each do |method| define_method method[:name], method[:block] end end end end |
#insert(name, klasses = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/method_repository.rb', line 33 def insert(name, klasses = {}, &block) if !klasses[:in] raise ArgumentError.new("`:in' parameter is required") end klasses[:in].each do |klass| @targets[klass] ||= [] @targets[klass] << { :name => name, :block => block, } end end |