Skip to content

Commit deef377

Browse files
committed
Merge pull request #7777 from amatsuda/file-to-path
2 parents 9697c15 + 91f9523 commit deef377

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎mrbgems/mruby-io/mrblib/file.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ class File < IO
22
# The path to the file
33
attr_accessor :path
44

5+
#
6+
# call-seq:
7+
# file.to_path -> filepath
8+
#
9+
# The path of the file, as File#path gives it: a File stands for its path
10+
# where an object with to_path is taken for one.
11+
#
12+
alias to_path path
13+
514
#
615
# call-seq:
716
# File.new(filename, mode="r") -> file

‎mrbgems/mruby-io/test/file.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ def assert_dirname_with_level(path, results)
5656
assert_true io.closed?
5757
end
5858

59+
assert('File#to_path') do
60+
File.open($mrbtest_io_rfname, "r") do |io|
61+
assert_equal $mrbtest_io_rfname, io.to_path
62+
end
63+
io = File.new(IO.sysopen($mrbtest_io_rfname), path: "given")
64+
assert_equal "given", io.to_path
65+
io.close
66+
end
67+
5968
assert('File.basename') do
6069
assert_equal '', File.basename('')
6170
assert_equal '/', File.basename('//')

0 commit comments

Comments
 (0)