summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-25 18:24:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-25 18:24:09 +0000
commit8335ce7065be10565e0c1fb8971df2b43d9d4d95 (patch)
treea0a9a8ab282bf416e8a4e8cff9bb1c125407f159 /ext/stringio
parent97f0b0f55818420b4c7a7002c92c08ad78a7e579 (diff)
* ext/io/console/console.c (io_getch): default delegating method
for StringIO. https://github.com/nobu/io-console/issues/4 * ext/stringio/stringio.c: moved some methods to hidden modules. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index ad18644..54d36c96 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -806,7 +806,7 @@ strio_ungetbyte(VALUE self, VALUE c)
static VALUE
strio_readchar(VALUE self)
{
- VALUE c = strio_getc(self);
+ VALUE c = rb_funcall2(self, rb_intern("getc"), 0, 0);
if (NIL_P(c)) rb_eof_error();
return c;
}
@@ -820,7 +820,7 @@ strio_readchar(VALUE self)
static VALUE
strio_readbyte(VALUE self)
{
- VALUE c = strio_getbyte(self);
+ VALUE c = rb_funcall2(self, rb_intern("getbyte"), 0, 0);
if (NIL_P(c)) rb_eof_error();
return c;
}
@@ -1037,7 +1037,7 @@ strio_gets(int argc, VALUE *argv, VALUE self)
static VALUE
strio_readline(int argc, VALUE *argv, VALUE self)
{
- VALUE line = strio_gets(argc, argv, self);
+ VALUE line = rb_funcall2(self, rb_intern("gets"), argc, argv);
if (NIL_P(line)) rb_eof_error();
return line;
}
@@ -1288,14 +1288,14 @@ strio_read(int argc, VALUE *argv, VALUE self)
static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
- VALUE val = strio_read(argc, argv, self);
+ VALUE val = rb_funcall2(self, rb_intern("read"), argc, argv);
if (NIL_P(val)) {
rb_eof_error();
}
return val;
}
-#define strio_syswrite strio_write
+#define strio_syswrite rb_io_write
/*
* call-seq:
@@ -1459,25 +1459,13 @@ Init_stringio()
rb_define_method(StringIO, "getc", strio_getc, 0);
rb_define_method(StringIO, "ungetc", strio_ungetc, 1);
rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1);
- rb_define_method(StringIO, "readchar", strio_readchar, 0);
rb_define_method(StringIO, "getbyte", strio_getbyte, 0);
- rb_define_method(StringIO, "readbyte", strio_readbyte, 0);
rb_define_method(StringIO, "gets", strio_gets, -1);
- rb_define_method(StringIO, "readline", strio_readline, -1);
rb_define_method(StringIO, "readlines", strio_readlines, -1);
rb_define_method(StringIO, "read", strio_read, -1);
- rb_define_method(StringIO, "sysread", strio_sysread, -1);
- rb_define_method(StringIO, "readpartial", strio_sysread, -1);
- rb_define_method(StringIO, "read_nonblock", strio_sysread, -1);
rb_define_method(StringIO, "write", strio_write, 1);
- rb_define_method(StringIO, "<<", strio_addstr, 1);
- rb_define_method(StringIO, "print", strio_print, -1);
- rb_define_method(StringIO, "printf", strio_printf, -1);
rb_define_method(StringIO, "putc", strio_putc, 1);
- rb_define_method(StringIO, "puts", strio_puts, -1);
- rb_define_method(StringIO, "syswrite", strio_syswrite, 1);
- rb_define_method(StringIO, "write_nonblock", strio_syswrite, 1);
rb_define_method(StringIO, "isatty", strio_isatty, 0);
rb_define_method(StringIO, "tty?", strio_isatty, 0);
@@ -1490,4 +1478,25 @@ Init_stringio()
rb_define_method(StringIO, "external_encoding", strio_external_encoding, 0);
rb_define_method(StringIO, "internal_encoding", strio_internal_encoding, 0);
rb_define_method(StringIO, "set_encoding", strio_set_encoding, -1);
+
+ {
+ VALUE mReadable = rb_define_module_under(rb_cIO, "readable");
+ rb_define_method(mReadable, "readchar", strio_readchar, 0);
+ rb_define_method(mReadable, "readbyte", strio_readbyte, 0);
+ rb_define_method(mReadable, "readline", strio_readline, -1);
+ rb_define_method(mReadable, "sysread", strio_sysread, -1);
+ rb_define_method(mReadable, "readpartial", strio_sysread, -1);
+ rb_define_method(mReadable, "read_nonblock", strio_sysread, -1);
+ rb_include_module(StringIO, mReadable);
+ }
+ {
+ VALUE mWritable = rb_define_module_under(rb_cIO, "writable");
+ rb_define_method(mWritable, "<<", strio_addstr, 1);
+ rb_define_method(mWritable, "print", strio_print, -1);
+ rb_define_method(mWritable, "printf", strio_printf, -1);
+ rb_define_method(mWritable, "puts", strio_puts, -1);
+ rb_define_method(mWritable, "syswrite", strio_syswrite, 1);
+ rb_define_method(mWritable, "write_nonblock", strio_syswrite, 1);
+ rb_include_module(StringIO, mWritable);
+ }
}