Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Forked from nahi/gist:751125
Created December 22, 2010 05:33
Show Gist options
  • Save BanzaiMan/751136 to your computer and use it in GitHub Desktop.
Save BanzaiMan/751136 to your computer and use it in GitHub Desktop.
require 'singleton'
loop do
classes = []
1000.times do
classes << Class.new do
include Singleton
end
end
(0..10).map do
Thread.new do
classes.each do |cls|
cls.instance
end
end
end.map(&:join)
puts "loop completed"
end
% ruby -v singleton_killer.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
singleton_killer.rb:18: undefined method `instance' for #<Class:0x1001896a0> (NoMethodError)
from singleton_killer.rb:1:in `join'
from singleton_killer.rb:1:in `to_proc'
from singleton_killer.rb:21:in `map'
from singleton_killer.rb:21
from singleton_killer.rb:5:in `loop'
from singleton_killer.rb:5
% ruby -v singleton_killer.rb
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
loop completed
loop completed
loop completed
loop completed
singleton_killer.rb:18: undefined method `instance' for #<Class:0x100348c70> (NoMethodError)
from singleton_killer.rb:1:in `join'
from singleton_killer.rb:1:in `to_proc'
from singleton_killer.rb:21:in `map'
from singleton_killer.rb:21
from singleton_killer.rb:5:in `loop'
from singleton_killer.rb:5
asari@ubuntu:~$ ruby -v singleton_killer.rb
ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
singleton_killer.rb:14: undefined method `instance' for #<Class:0x7fec77bd45c8> (NoMethodError)
from singleton_killer.rb:1:in `join'
from singleton_killer.rb:1:in `to_proc'
from singleton_killer.rb:17:in `map'
from singleton_killer.rb:17
from singleton_killer.rb:3:in `loop'
from singleton_killer.rb:3
[❼-1.8.7-p302]:~ $ ruby 751125.rb
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
751125.rb:14: undefined method `instance' for #<Class:0x100523630> (NoMethodError)
from 751125.rb:1:in `join'
from 751125.rb:1:in `to_proc'
from 751125.rb:17:in `map'
from 751125.rb:17
from 751125.rb:3:in `loop'
from 751125.rb:3
[❼-1.8.7-p302]:~ $ ruby -v 751125.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.5.0]
loop completed
751125.rb:14: undefined method `instance' for #<Class:0x100635730> (NoMethodError)
from 751125.rb:1:in `join'
from 751125.rb:1:in `to_proc'
from 751125.rb:17:in `map'
from 751125.rb:17
from 751125.rb:3:in `loop'
from 751125.rb:3
[❼-1.8.7-p302]:~ $ ruby -v 751125.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.5.0]
loop completed
loop completed
loop completed
751125.rb:14: undefined method `instance' for #<Class:0x1006119c0> (NoMethodError)
from 751125.rb:1:in `join'
from 751125.rb:1:in `to_proc'
from 751125.rb:17:in `map'
from 751125.rb:17
from 751125.rb:3:in `loop'
from 751125.rb:3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment