1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2006-10-18 04:30:40 +00:00
parent fd4b559c95
commit f87431ce95
2 changed files with 28 additions and 25 deletions

View file

@ -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]

View file

@ -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);
}
/*
* Document-method: each_line
* 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);
}
/*
* 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);