Project

General

Profile

Backport #3604

File.path, File.open, etc call to_str twice on the path argument

Added by tmat (Tomas Matousek) almost 9 years ago. Updated about 18 hours ago.

Status:
Closed
Priority:
Normal
[ruby-core:31451]

Description

=begin
class C
def respond_to?(name)
puts "C: #{name}"
return false
end
end

File.path(C.new) rescue p $!
File.open(C.new) rescue p $!
File.ctime(C.new) rescue p $!
File.dirname(C.new) rescue p $!

prints:

C: to_str
C: to_path
C: to_str
#
C: to_int
C: to_hash
C: to_str
C: to_path
C: to_str
#
C: to_io
C: to_str
C: to_path
C: to_str
#
C: to_str
C: to_path
C: to_str
#

Is there any reason why to_str is called twice on the arguments? Shouldn't to_path be called first and then to_str (i.e. the path conversion should be preferred over string conversion)?
=end


Related issues

Is duplicate of Ruby master - Bug #1760: Methods Expecting Paths Should Prefer #to_path Over #to_strClosed07/11/2009Actions

History

#1

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

  • Category set to core

=begin

=end

#2

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

  • Status changed from Open to Assigned
  • Assignee set to yugui (Yuki Sonoda)

=begin

=end

#3

Updated by jeremyevans0 (Jeremy Evans) about 18 hours ago

  • Status changed from Assigned to Closed
  • Description updated (diff)

Also available in: Atom PDF