I have a script that iterates using ObjectSpace#each_object with no args. Then it prints how many instances exist for each class.
I realized that some
I don't know about doing it in Ruby, but this is straightforward using the C API to Ruby. The RubyInline Gem makes adding bits of C to your Ruby code quite easy:
require 'inline'
class Example
inline do |builder|
builder.c_raw_singleton < 1
VALUE true_class(VALUE self, VALUE to_test) {
return rb_obj_class(to_test);
}
SRC
end
end
And then:
1.9.2p180 :033 > Example.true_class(20.minutes)
=> ActiveSupport::Duration