Skip to content

Commit

Permalink
Ensuring instances_within does not return duplicate objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Engel committed Jun 10, 2012
1 parent ea1000e commit 689ce37
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/mass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ def classes_within(mods, initial_array = nil)
def instances_within(*mods)
GC.start
[].tap do |array|
object_ids = []
if mods.empty?
ObjectSpace.each_object do |object|
array << object
unless object_ids.include? object.object_id
array << object
object_ids << object.object_id
end
end
else
classes_within(mods).each do |klass|
ObjectSpace.each_object(klass) do |object|
array << object
unless object_ids.include? object.object_id
array << object
object_ids << object.object_id
end
end
end
end
Expand Down

0 comments on commit 689ce37

Please sign in to comment.