Class: Mozart::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/mozart/composite.rb

Instance Method Summary collapse

Constructor Details

#initializeComposite

Returns a new instance of Composite.



5
6
7
# File 'lib/mozart/composite.rb', line 5

def initialize
  self.parts = []
end

Instance Method Details

#<<(part) ⇒ Object



9
10
11
# File 'lib/mozart/composite.rb', line 9

def <<(part)
  parts << part
end

#dispatch(message, *a, &b) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/mozart/composite.rb', line 17

def dispatch(message, *a, &b)
  target = recipient(message)
  
  unless target
    raise NotImplementedError, "No recipient implements #{message}" 
  end

  target.public_send(message, *a, &b)
end

#receives?(message) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mozart/composite.rb', line 13

def receives?(message)
  !!recipient(message)
end