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
51cf6b60
Commit
51cf6b60
authored
Sep 13, 2016
by
Tomoyuki Sahara
Committed by
GitHub
Sep 13, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #65 from ksss/join
Support Array argument
parents
d8189c2b
ff845be7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
32 deletions
+47
-32
mrblib/file.rb
mrblib/file.rb
+37
-24
test/file.rb
test/file.rb
+10
-8
No files found.
mrblib/file.rb
View file @
51cf6b60
...
...
@@ -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 @
51cf6b60
...
...
@@ -69,14 +69,16 @@ assert('IO#flock') do
end
assert
(
'File.join'
)
do
File
.
join
()
==
""
and
File
.
join
(
"a"
)
==
"a"
and
File
.
join
(
"/a"
)
==
"/a"
and
File
.
join
(
"a/"
)
==
"a/"
and
File
.
join
(
"a"
,
"b"
,
"c"
)
==
"a/b/c"
and
File
.
join
(
"/a"
,
"b"
,
"c"
)
==
"/a/b/c"
and
File
.
join
(
"a"
,
"b"
,
"c/"
)
==
"a/b/c/"
and
File
.
join
(
"a/"
,
"/b/"
,
"/c"
)
==
"a/b/c"
assert_equal
""
,
File
.
join
()
assert_equal
"a"
,
File
.
join
(
"a"
)
assert_equal
"/a"
,
File
.
join
(
"/a"
)
assert_equal
"a/"
,
File
.
join
(
"a/"
)
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"
])
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