Created
May 19, 2016 03:16
-
-
Save tagomoris/ffa517adc675ee91340f14a49817cc79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
MBA:~ tagomoris$ ruby objspace_test.rb | |
objspace_test.rb:14:in `block in <main>': can't convert Yay to Integer (Yay#to_int gives Yay) (TypeError) | |
from objspace_test.rb:12:in `each_object' | |
from objspace_test.rb:12:in `<main>' | |
MBA:~ tagomoris$ ruby -v | |
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15] |
This file contains hidden or 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
require 'objspace' | |
class Yay < BasicObject | |
def method_missing(name, *args, &block) | |
self | |
end | |
end | |
y = Yay.new | |
map = {} | |
ObjectSpace.each_object {|obj| | |
klass = obj.class rescue Object | |
if c = map[klass] | |
map[klass] = c + 1 | |
else | |
map[klass] = 1 | |
end | |
} | |
p map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment