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
7ff04945
Commit
7ff04945
authored
Mar 04, 2014
by
Paolo Bosetti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added File.foreach method.
Improved error management in File.new (Errno can be undefined)
parent
d9f3fd86
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
mrblib/file.rb
mrblib/file.rb
+18
-0
No files found.
mrblib/file.rb
View file @
7ff04945
...
...
@@ -12,9 +12,17 @@ class File < IO
if
fd_or_path
.
kind_of?
Fixnum
super
(
fd_or_path
,
mode
)
else
if
Object
.
const_defined?
:Errno
eclass
=
[
Errno
::
ENOENT
,
Errno
::
ENFILE
]
else
eclass
=
FileError
end
@path
=
fd_or_path
begin
fd
=
IO
.
sysopen
(
@path
,
mode
,
perm
)
rescue
RuntimeError
=>
e
raise
FileError
,
"Could not open file (
#{
e
}
)"
rescue
Errno
::
EMFILE
,
Errno
::
ENFILE
GC
.
start
fd
=
IO
.
sysopen
(
@path
,
mode
,
perm
)
...
...
@@ -119,6 +127,16 @@ class File < IO
end
end
def
self
.
foreach
(
file
)
if
block_given?
self
.
open
(
file
)
do
|
f
|
f
.
each
{
|
l
|
yield
l
}
end
else
return
self
.
new
(
file
)
end
end
def
self
.
directory?
(
file
)
FileTest
.
directory?
(
file
)
end
...
...
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