Skip to content

Commit 53dc421

Browse files
committed
addressed review
Promoted File#path to IO#path, added path: optional param to IO#new
1 parent b4a05b5 commit 53dc421

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/main/ruby/truffleruby/core/file.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,12 @@ class << self
11611161
def initialize(path_or_fd, mode = nil, perm = nil, **options)
11621162
if Primitive.is_a?(path_or_fd, Integer)
11631163
super(path_or_fd, mode, **options)
1164-
@path = nil
11651164
else
11661165
path = Truffle::Type.coerce_to_path path_or_fd
11671166
nmode, _binary, _external, _internal, _autoclose, perm = Truffle::IOOperations.normalize_options(mode, perm, options)
11681167
fd = IO.sysopen(path, nmode, perm)
11691168

1170-
@path = path
1169+
options[:path] = path
11711170
super(fd, mode, **options)
11721171
end
11731172
end
@@ -1208,9 +1207,6 @@ def stat
12081207
Stat.fstat Primitive.io_fd(self)
12091208
end
12101209

1211-
def path
1212-
@path.dup
1213-
end
12141210
alias_method :to_path, :path
12151211

12161212
def truncate(length)

src/main/ruby/truffleruby/core/io.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def initialize(fd, mode = nil, **options)
846846
@external = nil
847847
@pid = nil
848848

849-
mode, binary, external, internal, autoclose_tmp, _perm = Truffle::IOOperations.normalize_options(mode, nil, options)
849+
mode, binary, external, internal, autoclose_tmp, _perm, path = Truffle::IOOperations.normalize_options(mode, nil, options)
850850

851851
fd = Truffle::Type.coerce_to(fd, Integer, :to_int)
852852
sync = fd == 2 # stderr is always unbuffered, see setvbuf(3)
@@ -857,6 +857,7 @@ def initialize(fd, mode = nil, **options)
857857

858858
@autoclose = autoclose_tmp
859859
@pipe = false
860+
@path = path
860861
end
861862

862863
##
@@ -1221,6 +1222,10 @@ def prepare_read_string(str)
12211222
@lineno += 1
12221223
end
12231224

1225+
def path
1226+
@path.dup
1227+
end
1228+
12241229
##
12251230
# Return a string describing this IO object.
12261231
def inspect

src/main/ruby/truffleruby/core/truffle/io_operations.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,14 @@ def self.normalize_options(mode, perm, options, default_mode = nil)
543543
external, internal = encoding.split(':', 2)
544544
end
545545
end
546+
547+
unless Primitive.nil? options[:path]
548+
path = StringValue(options[:path])
549+
end
546550
end
547551
external = Encoding::BINARY if binary and !external and !internal
548552
perm ||= 0666
549-
[mode, binary, external, internal, autoclose, perm]
553+
[mode, binary, external, internal, autoclose, perm, path]
550554
end
551555
end
552556
end

0 commit comments

Comments
 (0)