Steve
1/31/2008 7:14:00 AM
You honestly shouldn't rely upon the programming language to do a lot of
guessing for you anyway...what if "string_1" happens to be a number,
i.e., "1", and object_2 is actually an integer, (say 5)? Should Ruby
"guess" that you want the output to be "1 5", or should it, (again
guess), that you want to convert your first argument to an integer and
thus produce 6 as your output? Of course the, (assumption), is that if
you want addition you'd be using integers in the first place, and not
strings, but that's not always the case and if you want automatic to_s,
there's an equally strong argument for to_i to operate the other way. In
either case, you're asking the language to guess what you, the programmer
want, and that would be a lot more counter-intuitive than convenient.
Steve
> Hi,
>
> In message "Re: ruby wish-list"
> on Thu, 31 Jan 2008 04:34:49 +0900, Roger Pack
> <rogerpack2005@gmail.com> writes:
>
> |I know this is controversial, but I wish that if you did |string_1 +
> object_2 (or any object) that it would just call .to_s on |object_2
> (instead of having to write it explicitly). I hate having to |write
> extra .to_s's (even if it avoids ambiguity). That's just me, but |hey
> :)
>
> It used to be behave like that. But it deferred the error detection, so
> I changed.
>
> matz.