# Apologies if this has been discussed already.  The archives don't  
seem to be searchable...

# This has bothered me about Ruby for years, but I feel I'm only just  
able to adequately enunciate it now.

# I would like it if modules were able to allow for the refashioning  
of any objects within its context, which also exist outside that  
context, such that any changes to an object apply only to that  
context, including for literals.

# In many respects this is quite similar to the change in the way  
block parameters are being handled now in Ruby 1.9 in contrast to Ruby  
1.8.

# For instance...

# String literals, '' and "", are bound to ::String, but should be  
contextually bound as is String.new('') to whatever module has  
refashioned the String constant.

# The way I would like it would allow for there being no requirement  
to do String.dup as I have done below, since any added methods to  
String automatically go into a module-specific meta-class.

# I'm aware of mixology, but that isn't quite enough.  And even to the  
extent that it is, it is less elegant than it working as I suggest.   
It really requires something in the core.

# And, is this a good idea anyway?

require 'pp'

module FunkyString

   String = ::String.dup

   original_instance_methods_before = ::String.instance_methods
   instance_methods_before = String.instance_methods
   literal_methods_before = ''.methods

   pp original_instance_methods_before.size
   pp instance_methods_before.size
   pp literal_methods_before.size

   class String
     def wow
       'wow'
     end
   end

   original_instance_methods_after = ::String.instance_methods
   instance_methods_after = String.instance_methods
   literal_methods_after = ''.methods

   pp original_instance_methods_after.size
   pp instance_methods_after.size
   pp literal_methods_after.size

   pp original_instance_methods_after - original_instance_methods_before
   pp instance_methods_after - instance_methods_before
   pp literal_methods_after - literal_methods_before

   class CantUseFunkyString
     def self.wow
       ''.wow # == ::String.new()
     end
   end

   class CanUseFunkyString
     def self.wow
       String.new('').wow
     end
   end

   begin
     puts CantUseFunkyString.wow
   rescue
     puts 'CantUseFunkyString'
   end

   puts CanUseFunkyString.wow

end