Class: Buschtelefon::Tattler
- Inherits:
-
Object
- Object
- Buschtelefon::Tattler
- Defined in:
- lib/buschtelefon/tattler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Instance Method Summary collapse
- #connect(tattler) ⇒ Object
- #feed(gossip) ⇒ Object
-
#initialize ⇒ Tattler
constructor
A new instance of Tattler.
- #knowledge ⇒ Object
- #load_messages(messages) ⇒ Object
- #transfer_knowledge(tattler) ⇒ Object
Constructor Details
#initialize ⇒ Tattler
Returns a new instance of Tattler.
5 6 7 8 |
# File 'lib/buschtelefon/tattler.rb', line 5 def initialize @connections = [] @brain = Brain.new end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
3 4 5 |
# File 'lib/buschtelefon/tattler.rb', line 3 def connections @connections end |
Instance Method Details
#connect(tattler) ⇒ Object
18 19 20 |
# File 'lib/buschtelefon/tattler.rb', line 18 def connect(tattler) @connections << tattler unless @connections.include?(tattler) end |
#feed(gossip) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/buschtelefon/tattler.rb', line 22 def feed(gossip) old_gossip = @brain.contains?(gossip) @brain << gossip # refresh memory return if old_gossip @connections.each { |tattler| tattler.feed(gossip) } end |
#knowledge ⇒ Object
14 15 16 |
# File 'lib/buschtelefon/tattler.rb', line 14 def knowledge @brain.to_a end |
#load_messages(messages) ⇒ Object
10 11 12 |
# File 'lib/buschtelefon/tattler.rb', line 10 def () .each { || @brain << Gossip.new() } end |
#transfer_knowledge(tattler) ⇒ Object
30 31 32 33 |
# File 'lib/buschtelefon/tattler.rb', line 30 def transfer_knowledge(tattler) connect(tattler) knowledge.each { |gossip| tattler.feed(gossip) } end |