Class: Gossip::Preteen

Inherits:
Object
  • Object
show all
Includes:
Gossip
Defined in:
lib/gossip/preteen.rb

Overview

A Preteen is someone who tells her Best Friends Forever some gossip. Each BFF is a Crony, but some Cronies can be out of favor during a particular invocation of a script. A Crony who’s out of favor is not told the gossip.

Constant Summary

Constants included from Gossip

CronyMaker, Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gossip

#when_not_TOTALLY_out_of_the_social_scene

Constructor Details

#initialize(cronymaker = {}, bff = [], on_the_outs_forever_and_ever_until_tomorrow = []) ⇒ Preteen

The second and third arguments are symbols that name Crony subclasses. (See Crony#symbol.) The first set will hear gossip; the second will not. The cronymaker is a hash. It is indexed by crony symbol. The values are blocks that first load the Crony subclass’s source, then return a new crony of that class.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gossip/preteen.rb', line 25

def initialize(cronymaker = {}, bff =[], on_the_outs_forever_and_ever_until_tomorrow=[])
  @cronies = []
  (bff+on_the_outs_forever_and_ever_until_tomorrow).each do | name |
    user_claims(cronymaker.has_key?(name)) {
      "#{name.inspect} is not a known crony."
    }
    crony = cronymaker[name].call
    crony.is_bff_by_default = bff.include?(name)
    accept(crony)
  end
end

Instance Attribute Details

#croniesObject (readonly)

Returns the value of attribute cronies.



18
19
20
# File 'lib/gossip/preteen.rb', line 18

def cronies
  @cronies
end

Instance Method Details

#accept(*cronies) ⇒ Object

:nodoc:



37
38
39
# File 'lib/gossip/preteen.rb', line 37

def accept(*cronies) # :nodoc: 
  @cronies += cronies
end

#tell_bffs(scandal, details) ⇒ Object

Tell Crony objects who are in favor (best friends forever) a scandal and its details. The scandal should be short - think an email Subject line.



44
45
46
47
48
# File 'lib/gossip/preteen.rb', line 44

def tell_bffs(scandal, details)
  simultaneously do | crony | 
    crony.hear(scandal, details) if crony.is_bff?
  end
end