From: Avdi Grimm Date: 2012-09-13T20:37:39+09:00 Subject: Re: Pathname#to_str withdrawn in 1.9? --bcaec501c572f78c3904c993bbae Content-Type: text/plain; charset=ISO-8859-1 I'd hazard a guess that the reasoning is because the '+' behavior was confusing and potentially surprising. Pathname defines '+' as a filename join, so Pathname('/foo') + Pathname('bar') == Pathname('/foo/bar'). But '/foo' + Pathname('bar') == '/foobar'. This is surprising and bug-prone if you have code that mixes pathnames and strings. I'd recommend sticking to interpolation for pathname/string concatenation; then it doesn't matter which object is what. On Sep 12, 2012 11:06 PM, "Jonathan Tran" wrote: > It's definitely a judgment call. Not sure if this helps you, but I think > most people use string interpolation, which calls #to_s implicitly. So I > think this would work just fine in 1.9: > > require "pathname" > f = Pathname("howdy") > p "well #{f}" > > > The use cases are like this: > > > > require "pathname" > > f = Pathname("howdy") > > p ("well " + f) > > > > Under 1.8.7 that's "well howdy". Under 1.9.3 it's an error, "can't > > convert Pathname into String." One wants to say: "Sure you can, just > > call to_s like you used to!" > > > > It's the breakage I don't understand. Why do our Benevolent Masters > > think this is just okay? I'll never find all the code where I'm doing > > this sort of thing... m. > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec501c572f78c3904c993bbae Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

I'd hazard a guess that the reasoning is because the '+' beh= avior was confusing and potentially surprising. Pathname defines '+'= ; as a filename join, so Pathname('/foo') + Pathname('bar')= =3D=3D Pathname('/foo/bar'). But '/foo' + Pathname('ba= r') =3D=3D '/foobar'. This is surprising and bug-prone if you h= ave code that mixes pathnames and strings.

I'd recommend sticking to interpolation for pathname/string concaten= ation; then it doesn't matter which object is what.

On Sep 12, 2012 11:06 PM, "Jonathan Tran&qu= ot; <lists@ruby-forum.com>= ; wrote:
It's definitely a judgment call. Not sure if this helps you, but I thin= k
most people use string interpolation, which calls #to_s implicitly. So I think this would work just fine in 1.9:

require "pathname"
f =3D Pathname("howdy")
p "well #{f}"

> The use cases are like this:
>
> require "pathname"
> f =3D Pathname("howdy")
> p ("well " + f)
>
> Under 1.8.7 that's "well howdy". Under 1.9.3 it's an= error, "can't
> convert Pathname into String." One wants to say: "Sure you c= an, just
> call to_s like you used to!"
>
> It's the breakage I don't understand. Why do our Benevolent Ma= sters
> think this is just okay? I'll never find all the code where I'= m doing
> this sort of thing... m.

--
Posted via http://= www.ruby-forum.com/.

--bcaec501c572f78c3904c993bbae--