diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-18 04:30:40 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-18 04:30:40 +0000 |
commit | f87431ce95461ce9552146cef2a1845db477b968 (patch) | |
tree | 6136f8b6851b416d37fb6b44c36d43b8267309dc | |
parent | fd4b559c95d4b3c36b4ab1724f6d7e9cf61d72b0 (diff) |
* string.c (rb_str_each_line): String#lines now works when a block
is given. in other words, lines become an alias to each_line.
[ruby-core:09218]
* string.c (rb_str_each_byte): ditto for bytes in place of lines.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | string.c | 45 |
2 files changed, 28 insertions, 25 deletions
@@ -1,3 +1,11 @@ +Wed Oct 18 13:25:50 2006 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (rb_str_each_line): String#lines now works when a block + is given. in other words, lines become an alias to each_line. + [ruby-core:09218] + + * string.c (rb_str_each_byte): ditto for bytes in place of lines. + Wed Oct 18 00:55:33 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (parser_yylex): use particular enums. [ruby-core:09221] @@ -3549,39 +3549,21 @@ rb_str_split(VALUE str, const char *sep0) /* + * Document-method: lines * call-seq: * str.lines(separator=$/) => anEnumerator + * str.lines(separator=$/) {|substr| block } => str * - * Returns an enumerator that gives each line in the string. + * Returns an enumerator that gives each line in the string. If a block is + * given, it iterates over eac line in the string. * * "foo\nbar\n".lines.to_a #=> ["foo\n", "bar\n"] * "foo\nb ar".lines.sort #=> ["b ar", "foo\n"] */ -static VALUE -rb_str_lines(int argc, VALUE *argv, VALUE str) -{ - return rb_enumeratorize(str, ID2SYM(rb_intern("each_line")), argc, argv); -} - -/* - * call-seq: - * str.bytes => anEnumerator - * - * Returns an enumerator that gives each byte in the string. - * - * "hello".bytes.to_a #=> [104, 101, 108, 108, 111] - */ - -static VALUE -rb_str_bytes(VALUE str) -{ - return rb_enumeratorize(str, ID2SYM(rb_intern("each_byte")), 0, 0); -} - /* + * Document-method: each_line * call-seq: - * str.each(separator=$/) {|substr| block } => str * str.each_line(separator=$/) {|substr| block } => str * * Splits <i>str</i> using the supplied parameter as the record separator @@ -3669,6 +3651,19 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) /* + * Document-method: bytes + * call-seq: + * str.bytes => anEnumerator + * str.bytes {|fixnum| block } => str + * + * Returns an enumerator that gives each byte in the string. If a block is + * given, it iterates over each byte in the string. + * + * "hello".bytes.to_a #=> [104, 101, 108, 108, 111] + */ + +/* + * Document-method: each_byte * call-seq: * str.each_byte {|fixnum| block } => str * @@ -4881,8 +4876,8 @@ Init_String(void) rb_define_method(rb_cString, "hex", rb_str_hex, 0); rb_define_method(rb_cString, "oct", rb_str_oct, 0); rb_define_method(rb_cString, "split", rb_str_split_m, -1); - rb_define_method(rb_cString, "lines", rb_str_lines, -1); - rb_define_method(rb_cString, "bytes", rb_str_bytes, 0); + rb_define_method(rb_cString, "lines", rb_str_each_line, -1); + rb_define_method(rb_cString, "bytes", rb_str_each_byte, 0); rb_define_method(rb_cString, "reverse", rb_str_reverse, 0); rb_define_method(rb_cString, "reverse!", rb_str_reverse_bang, 0); rb_define_method(rb_cString, "concat", rb_str_concat, 1); |