From: Lazaridis Ilias Date: 2011-06-07T18:42:34+09:00 Subject: [ruby-core:36809] [Ruby 1.9 - Feature #4845] Provide Class#cb_object_instantiated_from_literal(object) Issue #4845 has been updated by Lazaridis Ilias. Nobuyoshi Nakada wrote: > > * minimal overhead if not used (C-level if *ptr available, call) > > Not true. I admit I don't know your current implementation. Can you please point me to the relevant source code? And please rethink the "priority: low" of this issue. It seems to me that I have no way to intercept (literal) object instantiation. Or is there any way to do so? ---------------------------------------- Feature #4845: Provide Class#cb_object_instantiated_from_literal(object) http://redmine.ruby-lang.org/issues/4845 Author: Lazaridis Ilias Status: Assigned Priority: Low Assignee: Yukihiro Matsumoto Category: core Target version: (assuming that this is not a bug, but a speed tradeoff / known issue) class String alias_method :orig_initialize, :initialize def initialize(val) orig_initialize "OBSERVED: " + val end def my_method_test print self.inspect, " test\n" end end oo_string = String.new("The OO String") li_string = "The Literal String" print "Class: ", oo_string.class, " - content: ", oo_string, "\n" print "Class: ", li_string.class, " - content: ", li_string, "\n" oo_string.my_method_test li_string.my_method_test #OUTPUT #=> Class: String - content: OBSERVED: The OO String #=> Class: String - content: The Literal String #=> "OBSERVED: The OO String" test #=> "The Literal String" test - The li_string is an object of class String and responds to the added method "my_method_test". But: the initialize method of the modified String class was not called during instantiation. Is there any chance that this will be changed, thus the "initialize" method is called (if implemented)? If not, the suggestion would be: * provide a call-back Class#cb_object_instantiated_from_literal(object) (or similar) Benefits: * minimal overhead if not used (C-level if *ptr available, call) * allows simple notification about new objects. -- http://redmine.ruby-lang.org