I'm currently implementing an interner in the style of Guava's Interner, where:an intern pool is maintained for an immutable classwhenever a new instance of that class is created, it's checked to see if it's equal to an existing instance in the intern poolif such an existing instance is found, it's returned, otherwise the new instance is added to the pool and returnedOf course, in Ruby, you can replace methods like new and [], so my implementation does just that:module Interner  def self.extended(obj)    intern_pool = Hash.new do |hash, key|      # Ideally, this should be a deep freeze, but it's not supported      # (see http://bugs.ruby-lang.org/issues/show/2509).      if key.respond_to?(:clone)        key = key.clone        key.freeze if key.respond_to?(:freeze)      end      hash[key] = key    end    [:new, :[]].each do |name|      if obj.respond_to?(name)        obj.singleton_class.module_exec(obj.method(name)) do |orig|          define_method name do |*args, &block|            intern_pool[orig[*args, &block]]          end        end      end    end  endendExample usage:Foo = Struct.new :foo, :bar do  extend Internerenda = Foo[1, 2]b = Foo[3, 4]c = Foo.new(1, 2)d = Foo.new(3, 4)a.equal?(c)  # => trueb.equal?(d)  # => trueI realise that my implementation is less than perfect. What improvements can you recommend?
Ruby 1.9 interner
ruby;meta programming