Forum: Ruby on Rails Lohan the observable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
blinking bear (Guest)
on 2007-07-26 22:15
(Received via mailing list)
Sorry, that name is a misnomer.  However, I was excited to find that
Ruby
has a built in Observable module and I'm pretty bored, so I apologize in
advance....

require 'observer'

# one who is observed
class Celebrity
  include Observable

  attr_accessor :name
  attr_reader :is

  def is=(val)
    @is = val
    changed
    notify_observers(self)
  end
end

# one who does the observering
class TrashMag
  attr_accessor :name
  def update(sender)
    puts "#{name}'s Breaking News: OMG! #{sender.name} is #{sender.is}.
KeWl!!!!"
  end
end

celebs = []

lohan = Celebrity.new
lohan.name = "Lindsey Lohan"
celebs << lohan

britney = Celebrity.new
britney.name = "Britney Spears"
celebs << britney

paris = Celebrity.new
paris.name = "Paris Hilton"
celebs << paris

rags = ["People Magazine","US Weekly","InTouch","CNN"].each do |name|
  mag = TrashMag.new
  mag.name = name
  celebs.each { |celeb| celeb.add_observer(mag) }
end


lohan.is =   "trying to score coke while driving under the influence."
britney.is = "attempting another comeback sans undergarments"
paris.is =   "such a morally sound person now that she's been through
jail"
blinking bear (Guest)
on 2007-07-26 22:16
(Received via mailing list)
output:

People Magazine's Breaking News: OMG! Lindsey Lohan is trying to score
coke
while under the influence.. KeWl!!!!
US Weekly's Breaking News: OMG! Lindsey Lohan is trying to score coke
while
under the influence.. KeWl!!!!
InTouch's Breaking News: OMG! Lindsey Lohan is trying to score coke
while
under the influence.. KeWl!!!!
CNN's Breaking News: OMG! Lindsey Lohan is trying to score coke while
under
the influence.. KeWl!!!!
People Magazine's Breaking News: OMG! Britney Spears is attempting
another
comeback . KeWl!!!!
US Weekly's Breaking News: OMG! Britney Spears is attempting another
comeback . KeWl!!!!
InTouch's Breaking News: OMG! Britney Spears is attempting another
comeback
. KeWl!!!!
CNN's Breaking News: OMG! Britney Spears is attempting another comeback
.
KeWl!!!!
People Magazine's Breaking News: OMG! Paris Hilton is such a stronger
person
now that she's been through jail. KeWl!!!!
US Weekly's Breaking News: OMG! Paris Hilton is such a stronger person
now
that she's been through jail. KeWl!!!!
InTouch's Breaking News: OMG! Paris Hilton is such a stronger person now
that she's been through jail. KeWl!!!!
CNN's Breaking News: OMG! Paris Hilton is such a stronger person now
that
she's been through jail. KeWl!!!!
This topic is locked and can not be replied to.