Skip to content

Instantly share code, notes, and snippets.

@brianroth
Created February 6, 2012 21:44
Show Gist options
  • Save brianroth/1755095 to your computer and use it in GitHub Desktop.
Save brianroth/1755095 to your computer and use it in GitHub Desktop.
Fruit Basket
#!/usr/bin/ruby
module Round
end
class Fruit
end
module NotRound
end
class Apple < Fruit
include Round
end
class Orange < Fruit
include Round
end
class Banana < Fruit
include NotRound
end
fruit = Array.new
count = 0
while count < 10000
if (count % 2) == 0
fruit << Orange.new
end
if (count % 3) == 0
fruit << Banana.new
end
fruit << Apple.new
if ((count % 50) == 0)
puts("MODEL_COUNT: performing counts, count=#{count}")
objs = {}
ObjectSpace.each_object(Fruit) do |o|
objs[o.class] ||= 0
objs[o.class] += 1
end
objs.each do |clazz, obj_count|
puts("MODEL_COUNT: #{clazz.name} #{obj_count}")
end
end
count += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment