lib/buschtelefon/tattler.rb in buschtelefon-0.1.0 vs lib/buschtelefon/tattler.rb in buschtelefon-0.2.0
- old
+ new
@@ -5,19 +5,27 @@
def initialize
@connections = []
@brain = Brain.new
end
+ def knowledge
+ @brain.to_a
+ end
+
def connect(tattler)
- @connections << tattler
- @connections.uniq!
+ @connections << tattler unless @connections.include?(tattler)
end
def feed(gossip)
old_gossip = @brain.contains?(gossip)
@brain << gossip # refresh memory
return if old_gossip
@connections.each { |tattler| tattler.feed(gossip) }
+ end
+
+ def transfer_knowledge(tattler)
+ connect(tattler)
+ knowledge.each { |gossip| tattler.feed(gossip) }
end
end
end