From: Gary Weaver Date: 2012-09-26T03:13:33+09:00 Subject: could initialize return an existing object instead of a new instance? Is it possible for initialize to return an existing object instead of a new instance? Specifically curious about whether it would be possible to implement a StringPool in Ruby such that the same object with same object_id would be returned if you tried to construct with the same value, unless a bang method (like chomp!) were called on the object in which case instead of returning the same object instance from the bang method, it would return a different object instance. I told someone that this would be a massive change since it would break these two assumptions: s = "Hello" s2 = "Hello" # s.object_id != s2.object_id s = "Hello" original_object_id = s.object_id s.chomp!('o') # original_object_id == s.object_id But, maybe if it were possible to develop this as a gem, people could use at their own risk. Also, it just seemed like a neat idea (not that it would work in the String case?) if you could do something in the initializer to abandon the instance that was being created and instead return a different object from the initializer, like one that already exists. Even if this isn't possible currently, what issues would one run into trying to implement support for this? Thanks! -- Posted via http://www.ruby-forum.com/.