Project

General

Profile

Feature #4780

String#split with a block

Added by yimutang (Joey Zhou) over 7 years ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:36466]

Description

Mentioned before, in another (rejected) issue thread: http://redmine.ruby-lang.org/issues/4615

There are a few methods, which return an array without a trailing block, or also can be iterated with a block.

Such as String#scan.

String#split has only one form:

str.split(pattern=$;, limit=0) -> array

Maybe add a iterative form, when with a block:

str.split(pattern=$;, limit=0) {|field| ... } -> str

If the string is very long, and I only need to play with the splitted string one by one, this will not create a useless expensive array.

Joey


Related issues

Related to Ruby trunk - Feature #4615: Add IO#split and iterative form of String#splitRejected04/26/2011

Associated revisions

Revision 2258a97f
Added by nobu (Nobuyoshi Nakada) 9 months ago

string.c: split with block

  • string.c (rb_str_split_m): yield each split substrings if the block is given, instead of returing the array. [Feature #4780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62763
Added by nobu (Nobuyoshi Nakada) 9 months ago

string.c: split with block

  • string.c (rb_str_split_m): yield each split substrings if the block is given, instead of returing the array. [Feature #4780]

Revision 1bf9dec0
Added by nobu (Nobuyoshi Nakada) 9 months ago

string.c: [DOC] split with block [ci skip]

  • string.c (rb_str_split_m): [DOC] about split with block. [Feature #4780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62790
Added by nobu (Nobuyoshi Nakada) 9 months ago

string.c: [DOC] split with block [ci skip]

  • string.c (rb_str_split_m): [DOC] about split with block. [Feature #4780]

History

#1 [ruby-core:36510] Updated by naruse (Yui NARUSE) over 7 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

#2 [ruby-core:49149] Updated by mame (Yusuke Endoh) about 6 years ago

  • Target version set to 2.6

#3 Updated by naruse (Yui NARUSE) 12 months ago

  • Target version deleted (2.6)

#4 [ruby-core:86138] Updated by matz (Yukihiro Matsumoto) 9 months ago

Accepted.

Matz.

#5 Updated by nobu (Nobuyoshi Nakada) 9 months ago

  • Description updated (diff)

#6 Updated by nobu (Nobuyoshi Nakada) 9 months ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r62763.


string.c: split with block

  • string.c (rb_str_split_m): yield each split substrings if the block is given, instead of returing the array. [Feature #4780]

Also available in: Atom PDF