summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-io')
-rw-r--r--mrbgems/mruby-io/mrblib/io.rb33
-rw-r--r--mrbgems/mruby-io/src/io.c2
2 files changed, 5 insertions, 30 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb
index 006578222..9192d7bf2 100644
--- a/mrbgems/mruby-io/mrblib/io.rb
+++ b/mrbgems/mruby-io/mrblib/io.rb
@@ -26,11 +26,11 @@ class IO
end
end
- def self.popen(command, mode = 'r', opts={}, &block)
+ def self.popen(command, mode = 'r', **opts, &block)
if !self.respond_to?(:_popen)
raise NotImplementedError, "popen is not supported on this platform"
end
- io = self._popen(command, mode, opts)
+ io = self._popen(command, mode, **opts)
return io unless block
begin
@@ -61,39 +61,14 @@ class IO
end
end
- def self.read(path, length=nil, offset=nil, opt=nil)
- if not opt.nil? # 4 arguments
- offset ||= 0
- elsif not offset.nil? # 3 arguments
- if offset.is_a? Hash
- opt = offset
- offset = 0
- else
- opt = {}
- end
- elsif not length.nil? # 2 arguments
- if length.is_a? Hash
- opt = length
- offset = 0
- length = nil
- else
- offset = 0
- opt = {}
- end
- else # only 1 argument
- opt = {}
- offset = 0
- length = nil
- end
-
+ def self.read(path, length=nil, offset=0, mode: "r")
str = ""
fd = -1
io = nil
begin
if path[0] == "|"
- io = IO.popen(path[1..-1], (opt[:mode] || "r"))
+ io = IO.popen(path[1..-1], mode)
else
- mode = opt[:mode] || "r"
fd = IO.sysopen(path, mode)
io = IO.open(fd, mode)
end
diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c
index 3229d339a..8261cf998 100644
--- a/mrbgems/mruby-io/src/io.c
+++ b/mrbgems/mruby-io/src/io.c
@@ -363,7 +363,7 @@ mrb_io_s_popen_args(mrb_state *mrb, mrb_value klass,
NULL,
};
- mrb_get_args(mrb, "z|o:", cmd, &mode, &kw);
+ mrb_get_args(mrb, "zo:", cmd, &mode, &kw);
*flags = mrb_io_mode_to_flags(mrb, mode);
*doexec = (strcmp("-", *cmd) != 0);