On Fri, Sep 09, 2005 at 03:49:59AM +0900, Eric Mahurin wrote:
> class String
>   def self.from(obj); obj.to_s; end
>   def to(klass); klass.from_s(self); end
> end
> 
> If you did this, then I guess you could consider this the
> overhead for each class that other classes want to convert
> to/from - String, Integer, Float, Array, etc.
> 
> I would think this more straight-forward approach would be more
> likely accepted.

Would you be more amenable to a solution like:

  class Object
    def to(type, *args, &block)
      return send("to_#{type}", *args, &block)
    end

    def to_String
      return to_s
    end
  end

  class String
    def to_Integer
      return Integer(self)
    end

    # etc.
  end

This eliminates the global constant by using double-dispatch, plus
retains the ability to convert to a non-class type (e.g.
foo.to(Enumerable)).

Paul