# Lohan the observable

**URL:** <https://www.ruby-forum.com/t/lohan-the-observable/110489>\
**Category:** Rails\
**Created:** [July 26, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/lohan-the-observable/110489 "2007-07-26T20:15:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blinking\_bear](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a9a28c/32.png) [@blinking\_bear](https://www.ruby-forum.com/u/blinking_bear)\
**Post date:** [July 26, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/lohan-the-observable/110489/1 "2007-07-26T20:15:12Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![blinking\_bear](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a9a28c/32.png) [@blinking\_bear](https://www.ruby-forum.com/u/blinking_bear)\
**Post date:** [July 26, 2007, 8:16pm UTC](https://www.ruby-forum.com/t/lohan-the-observable/110489/2 "2007-07-26T20:16:12Z")

</div>

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!!!
