Created
September 7, 2012 13:30
-
-
Save jondot/3666265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby test.rb | |
97 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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