lib/mass.rb in ruby-mass-0.1.1 vs lib/mass.rb in ruby-mass-0.1.2
- old
+ new
@@ -31,11 +31,11 @@
# Returns a hash containing classes with the object_ids of its instances currently in the Ruby Heap. You can narrow the result by namespace.
#
def index(*mods)
instances_within(*mods).inject({}) do |hash, object|
- ((hash[object.class.name] ||= []) << object.object_id).sort!
+ ((hash[object.class.name] ||= []) << object.object_id).sort! if object.respond_to?(:class)
hash
end
end
# Returns a hash containing classes with the amount of its instances currently in the Ruby Heap. You can narrow the result by namespace.
@@ -48,22 +48,20 @@
end
# Prints all object instances within either the whole environment or narrowed by namespace group by class.
#
def print(*mods)
- count(*mods).tap do |stats|
- puts "\n"
- puts "=" * 50
- puts " Objects within #{mods ? "#{mods.collect(&:name).sort} namespace" : "environment"}"
- puts "=" * 50
- stats.keys.sort{|a, b| [stats[b], a] <=> [stats[a], b]}.each do |key|
- puts " #{key}: #{stats[key]}"
- end
- puts " - no objects instantiated -" if stats.empty?
- puts "=" * 50
- puts "\n"
+ stats = count(*mods)
+ puts "\n"
+ puts "=" * 50
+ puts " Objects within #{mods ? "#{mods.collect(&:name).sort} namespace" : "environment"}"
+ puts "=" * 50
+ stats.keys.sort{|a, b| [stats[b], a] <=> [stats[a], b]}.each do |key|
+ puts " #{key}: #{stats[key]}"
end
- nil
+ puts " - no objects instantiated -" if stats.empty?
+ puts "=" * 50
+ puts "\n"
end
# Returns all references to the passed object. You can narrow the namespace of the objects referencing to the object.
#
# ==== Example
\ No newline at end of file