Module: Such::Part

Defined in:
lib/such/part.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(plug, *args) ⇒ Object

assuming a plug



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/such/part.rb', line 17

def method_missing(plug,*args) # assuming a plug
  super unless args.length==0 and plug=~/^[^\W_]+_[^\W_]+$/
  obj = nil
  self.class.plugs.each do |plg|
    plug = method(plg).call
    if plug.is_a? Such::Part
      break if obj = plug.method(plg).call
    end
  end
  return obj
end

Instance Method Details

#initialize(*parameters, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/such/part.rb', line 3

def initialize(*parameters, &block)
  super(*parameters)
  self.class.plugs.each do |plg|
    if /^(?<sym>[^\W_]+)_(?<cls>[^\W_]+)$/=~plg
      plg, sym, cls = method("#{plg}="), "#{sym}!".to_sym, Object.const_get("Such::#{cls}")
      plg.call cls.new(self, sym, &block)
    end
  end
end

#message(*parameters) ⇒ Object



13
14
15
# File 'lib/such/part.rb', line 13

def message(*parameters)
  self.class.plugs.each{|plg| method(plg).call.message(*parameters)}
end