summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 594813cbc0..da4eb964cb 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -921,18 +921,17 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
{
const char *s, *e, *p;
long n, limit = 0;
- VALUE str;
+ VALUE str, lim;
- if (argc == 0) {
+ rb_scan_args(argc, argv, "02", &str, &lim);
+ switch (argc) {
+ case 0:
str = rb_rs;
- }
- else {
- VALUE lim, tmp;
+ break;
- rb_scan_args(argc, argv, "11", &str, &lim);
- if (!NIL_P(lim)) limit = NUM2LONG(lim);
- else if (!NIL_P(str) && TYPE(str) != T_STRING) {
- tmp = rb_check_string_type(str);
+ case 1:
+ if (!NIL_P(str) && TYPE(str) != T_STRING) {
+ VALUE tmp = rb_check_string_type(str);
if (NIL_P(tmp)) {
limit = NUM2LONG(str);
if (limit == 0) return rb_str_new(0,0);
@@ -942,9 +941,12 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
str = tmp;
}
}
- else if (!NIL_P(str)) {
- StringValue(str);
- }
+ break;
+
+ case 2:
+ if (!NIL_P(str)) StringValue(str);
+ limit = NUM2LONG(lim);
+ break;
}
if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) {