Pathname #+ just coerces the argument to a pathname before
concatenating, so that it can return another pathname instance. The
problem with Mislav's example is the preceding "/" on "/tmp/foo":
>> (Rails.root + "/tmp/foo").to_s
=> "/tmp/foo"
>> (Rails.root + "tmp/foo").to_s
=> "/Users/geoff/Sites/edgerails/tmp/foo"
Not intuitive, I agree. String interpolation, however, works as
expected:
>> "#{Rails.root}/tmp/foo"
=> "/Users/geoff/Sites/edgerails/tmp/foo"
On Dec 8, 12:21 pm, Ryan Bates <[EMAIL PROTECTED]> wrote:
> I do think this should be addressed. Why is the "+" operator
> overridden in Pathname in the first place? Is there some benefit to
> this way of concatenating that I'm not seeing? Rails.root + "/foo"
> should append "/foo" to the end of Rails.root. That's what the code
> says anyway.
>
> Regards,
>
> Ryan
>
> On Dec 8, 4:37 am, Chris Cruft <[EMAIL PROTECTED]> wrote:
>
> > I know of at least two of my apps that will break. But I also agree
> > with the sentiment of
> > dealing with a slightly higher abstraction than just strings when
> > working with the filesystem.
> > So I'm willing to pay the (small) price and I thank you for bringing
> > it to my attention!
>
> > On Dec 7, 5:10 pm, "Mislav Marohnić" <[EMAIL PROTECTED]>
> > wrote:
>
> > > Changing Rails.root to a Pathname was great and all (I'm a strong believer
> > > that us Rubyists shouldn't handle paths or URLs as String objects), but
> > > there's one thing I've discovered just now that kinda ruins the joy.
> > > With string paths, these two lines are equivalent:
>
> > > "#{Rails.root}/tmp/foo"
> > > Rails.root + "/tmp/foo"
>
> > > Now that Rails.root is a Pathname, they do totally different things. While
> > > the first one becomes "/path/to/app/tmp/foo", the second becomes just
> > > "/tmp/foo" because Pathname overloads the "+" operator in a similar way
> > > that
> > > URI does it.
>
> > > Thoughts? Think this may break apps? It broke mine, but I'm not
> > > complaining
> > > -- being subscribed to edge commits helps me resolve these kinds of issues
> > > in a matter of seconds. To other folks upgrading to 2.3, this may take
> > > much
> > > longer to track down.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---