io.rb,print.rb: `puts` to expand array arguments.
As CRuby behaves.
MODIFY
mrbgems/mruby-io/mrblib/io.rb
mrbgems/mruby-io/mrblib/io.rb
@@ -360,9 +360,14 @@ class IO
i = 0
len = args.size
while i < len
- s = args[i].to_s
+ s = args[i]
+ if s.kind_of?(Array)
+ puts(*s)
+ else
+ s = s.to_s
write s
write "\n" if (s[-1] != "\n")
+ end
i += 1
end
write "\n" if len == 0

MODIFY
mrbgems/mruby-print/mrblib/print.rb
mrbgems/mruby-print/mrblib/print.rb
@@ -19,6 +19,37 @@ module Kernel
args.__svalue
end
+ # 15.3.1.2.10
+ # 15.3.1.3.35
+ def print(*args)
+ i = 0
+ len = args.size
+ while i < len
+ __printstr__ args[i].to_s
+ i += 1
+ end
+ end
+
+ # 15.3.1.2.11
+ # 15.3.1.3.39
+ def puts(*args)
+ i = 0
+ len = args.size
+ while i < len
+ s = args[i]
+ if s.kind_of?(Array)
+ puts(*s)
+ else
+ s = s.to_s
+ __printstr__ s
+ __printstr__ "\n" if (s[-1] != "\n")
+ end
+ i += 1
+ end
+ __printstr__ "\n" if len == 0
+ nil
+ end
+
def printf(*args)
__printstr__(sprintf(*args))
nil

MODIFY
mrbgems/mruby-print/src/print.c
mrbgems/mruby-print/src/print.c
@@ -47,53 +47,12 @@ mrb_printstr(mrb_state *mrb, mrb_value self)
return s;
}
-/* 15.3.1.2.10 */
-/* 15.3.1.3.35 */
-static mrb_value
-mrb_print(mrb_state *mrb, mrb_value self)
-{
- mrb_int argc, i;
- const mrb_value *argv;
-
- mrb_get_args(mrb, "*", &argv, &argc);
- for (i=0; i<argc; i++) {
- mrb_value s = mrb_obj_as_string(mrb, argv[i]);
- printstr(mrb, RSTRING_PTR(s), RSTRING_LEN(s));
- }
- return mrb_nil_value();
-}
-
-/* 15.3.1.2.11 */
-/* 15.3.1.3.39 */
-static mrb_value
-mrb_puts(mrb_state *mrb, mrb_value self)
-{
- mrb_int argc, i;
- const mrb_value *argv;
-
- mrb_get_args(mrb, "*", &argv, &argc);
- for (i=0; i<argc; i++) {
- mrb_value s = mrb_obj_as_string(mrb, argv[i]);
- mrb_int len = RSTRING_LEN(s);
- printstr(mrb, RSTRING_PTR(s), len);
- if (len == 0 || RSTRING_PTR(s)[len-1] != '\n') {
- printstr(mrb, "\n", 1);
- }
- }
- if (argc == 0) {
- printstr(mrb, "\n", 1);
- }
- return mrb_nil_value();
-}
-
void
mrb_mruby_print_gem_init(mrb_state* mrb)
{
struct RClass *krn;
krn = mrb->kernel_module;
mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, MRB_ARGS_REQ(1));
- mrb_define_method(mrb, krn, "print", mrb_print, MRB_ARGS_ANY());
- mrb_define_method(mrb, krn, "puts", mrb_puts, MRB_ARGS_ANY());
}
void

io.rb,print.rb: `puts` to expand array arguments.

As CRuby behaves.