Remove $/ from mruby implementation.

1. `$/` and other Perl-ish global variables are not defined in ISO.
2. The current Ruby policy do not encourage those variables.
3. Those variables has global effect and can cause troubles.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-09-12 21:22:59 +09:00
parent 6bbdb97e75
commit 231a1d68b0
3 changed files with 5 additions and 9 deletions
+3 -3
View File
@@ -226,12 +226,12 @@ class IO
end
end
def readline(arg = $/, limit = nil)
def readline(arg = "\n", limit = nil)
case arg
when String
rs = arg
when Fixnum
rs = $/
rs = "\n"
limit = arg
else
raise ArgumentError
@@ -242,7 +242,7 @@ class IO
end
if rs == ""
rs = $/ + $/
rs = "\n\n"
end
array = []
-3
View File
@@ -1328,7 +1328,4 @@ mrb_init_io(mrb_state *mrb)
mrb_define_method(mrb, io, "closed?", mrb_io_closed, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
mrb_define_method(mrb, io, "pid", mrb_io_pid, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
mrb_define_method(mrb, io, "fileno", mrb_io_fileno, MRB_ARGS_NONE());
mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$/"), mrb_str_new_cstr(mrb, "\n"));
}
+2 -3
View File
@@ -1529,9 +1529,8 @@ mrb_str_chomp_bang(mrb_state *mrb, mrb_value str)
* str.chomp(separator="\n") => new_str
*
* Returns a new <code>String</code> with the given record separator removed
* from the end of <i>str</i> (if present). If <code>$/</code> has not been
* changed from the default Ruby record separator, then <code>chomp</code> also
* removes carriage return characters (that is it will remove <code>\n</code>,
* from the end of <i>str</i> (if present). <code>chomp</code> also removes
* carriage return characters (that is it will remove <code>\n</code>,
* <code>\r</code>, and <code>\r\n</code>).
*
* "hello".chomp #=> "hello"