From: GOTO Kentaro Date: 2002-10-02T04:25:29+09:00 Subject: Re: thoughts on typelessness At Wed, 2 Oct 2002 03:54:25 +0900, Paul Brannan wrote: > > On Wed, Oct 02, 2002 at 02:43:22AM +0900, GOTO Kentaro wrote: > > Hmm, the name to_flt looks to be called by "%f" % obj. How about > > to_array, to_hash, to_integer and to_string for the name of default > > dispatch of Array(), Hash(), Integer() and String() respectively? > > A grep for to_flt in the Ruby source comes up empty. Where are you > seeing to_flt get called? Sorry for my unclear English. to_str or to_ary are used as default implicit conversion method. For example, obj.to_str would be called by "%s" % obj. Then I thought that an implicit conversion should differ from strict conversion. I'd like to propose a new mechanism general purpose: obj.to_a implicit conversion: obj.to_ary # called by *obj strict conversion: obj.to_array # called by Array() In this mechanism, to_flt would be positioned at implicit conversion. An implicit to_flt conversion MAY call to_f as its default definition. And to_flt MAY also be distinct from to_float. With this mechanism we can customize them, e.g., obj.to_f #=> 1.23 "%f" % obj #=> "1.23" if obj.to_flt == 1.23 Float(obj) #=> raise an ArgumentError Is it overkill? -- Gotoken