Module: Such::Part
- Defined in:
- lib/such/part.rb
Constant Summary collapse
- PLUG_PATTERN =
/^(?<sym>[^\W_]+)_(?<cls>[^\W_]+)$/
Instance Method Summary collapse
- #initialize(*parameters, &block) ⇒ Object
- #message(*parameters) ⇒ Object
-
#method_missing(maybe, *args) ⇒ Object
maybe a plug down the plugged things.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(maybe, *args) ⇒ Object
maybe a plug down the plugged things.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/such/part.rb', line 20 def method_missing(maybe,*args) # maybe a plug down the plugged things. super unless args.length==0 and PLUG_PATTERN.match?(maybe) self.class.plugs.each do |plug| thing = public_send(plug) if thing.is_a? Such::Part if obj = thing.public_send(maybe) return obj end end end return nil end |
Instance Method Details
#initialize(*parameters, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/such/part.rb', line 5 def initialize(*parameters, &block) super(*parameters) self.class.plugs.each do |plg| if md = PLUG_PATTERN.match(plg) plg, sym, cls = "#{plg}=".to_sym, "#{md[:sym]}!".to_sym, Object.const_get("Such::#{md[:cls]}") # self.<plg> = Such::<cls>.new(self, :<sym>!, &block) public_send plg, cls.new(self, sym, &block) end end end |
#message(*parameters) ⇒ Object
16 17 18 |
# File 'lib/such/part.rb', line 16 def (*parameters) self.class.plugs.each{|plg| public_send(plg).(*parameters) } end |