Skip to content

Instantly share code, notes, and snippets.

@jondot
Created September 7, 2012 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jondot/3666265 to your computer and use it in GitHub Desktop.
Save jondot/3666265 to your computer and use it in GitHub Desktop.
module MyLibrary
# nasty static variable
BigBallOfMud = { :woofed => 0 }
end
class Puppy
def woof!
puts "woof!"
# for book keeping
MyLibrary::BigBallOfMud[:woofed] += 1
end
end
pup = Puppy.new
# eventhough pup isn't static and is cute, woof! is still pretty nasty because
# it accesses a static variable.
pup.woof!
$ ruby test.rb
97
100.times do
Thread.new do
pup.woof!
end
end
sleep(5)
puts MyLibrary::BigBallOfMud[:woofed]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment