Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
ff845be7
Unverified
Commit
ff845be7
authored
Sep 11, 2016
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support Array argument
parent
7c9d9410
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
24 deletions
+39
-24
mrblib/file.rb
mrblib/file.rb
+37
-24
test/file.rb
test/file.rb
+2
-0
No files found.
mrblib/file.rb
View file @
ff845be7
...
...
@@ -19,34 +19,47 @@ class File < IO
end
def
self
.
join
(
*
names
)
if
names
.
size
==
0
""
elsif
names
.
size
==
1
names
[
0
]
else
if
names
[
0
][
-
1
]
==
File
::
SEPARATOR
s
=
names
[
0
][
0
..-
2
]
else
s
=
names
[
0
].
dup
end
(
1
..
names
.
size
-
2
).
each
{
|
i
|
t
=
names
[
i
]
if
t
[
0
]
==
File
::
SEPARATOR
and
t
[
-
1
]
==
File
::
SEPARATOR
t
=
t
[
1
..-
2
]
elsif
t
[
0
]
==
File
::
SEPARATOR
t
=
t
[
1
..-
1
]
elsif
t
[
-
1
]
==
File
::
SEPARATOR
t
=
t
[
0
..-
2
]
return
""
if
names
.
empty?
names
.
map!
do
|
name
|
case
name
when
String
name
when
Array
if
names
==
name
raise
ArgumentError
,
"recursive array"
end
s
+=
File
::
SEPARATOR
+
t
if
t
!=
""
}
if
names
[
-
1
][
0
]
==
File
::
SEPARATOR
s
+=
File
::
SEPARATOR
+
names
[
-
1
][
1
..-
1
]
join
(
*
name
)
else
s
+=
File
::
SEPARATOR
+
names
[
-
1
]
raise
TypeError
,
"no implicit conversion of
#{
name
.
class
}
into String"
end
s
end
return
names
[
0
]
if
names
.
size
==
1
if
names
[
0
][
-
1
]
==
File
::
SEPARATOR
s
=
names
[
0
][
0
..-
2
]
else
s
=
names
[
0
].
dup
end
(
1
..
names
.
size
-
2
).
each
{
|
i
|
t
=
names
[
i
]
if
t
[
0
]
==
File
::
SEPARATOR
and
t
[
-
1
]
==
File
::
SEPARATOR
t
=
t
[
1
..-
2
]
elsif
t
[
0
]
==
File
::
SEPARATOR
t
=
t
[
1
..-
1
]
elsif
t
[
-
1
]
==
File
::
SEPARATOR
t
=
t
[
0
..-
2
]
end
s
+=
File
::
SEPARATOR
+
t
if
t
!=
""
}
if
names
[
-
1
][
0
]
==
File
::
SEPARATOR
s
+=
File
::
SEPARATOR
+
names
[
-
1
][
1
..-
1
]
else
s
+=
File
::
SEPARATOR
+
names
[
-
1
]
end
s
end
def
self
.
expand_path
(
path
,
default_dir
=
'.'
)
...
...
test/file.rb
View file @
ff845be7
...
...
@@ -77,6 +77,8 @@ assert('File.join') do
assert_equal
"/a/b/c"
,
File
.
join
(
"/a"
,
"b"
,
"c"
)
assert_equal
"a/b/c/"
,
File
.
join
(
"a"
,
"b"
,
"c/"
)
assert_equal
"a/b/c"
,
File
.
join
(
"a/"
,
"/b/"
,
"/c"
)
assert_equal
"a/b/c"
,
File
.
join
([
"a"
,
"b"
,
"c"
])
assert_equal
"a/b/c"
,
File
.
join
(
"a"
,
[
"b"
,
[
"c"
]])
end
assert
(
'File.realpath'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment