[Feature #2017] String#/(sep)

Feature #2017: String#/(sep)
http://redmine.ruby-lang.org/issues/show/2017

e$B5/I<<Te(B: Yui NARUSE
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core

String#/(separator) e$B$re(B String#join(separator) e$B$Ne(B alias
e$B$H$7$FDI2C$7$^$;$s$+e(B?

e$B0JA0$+$i!"e(BArray#*(sep) e$B$H$NBP>[email protected]$+$ie(B String#/(sep)
e$B$N:NMQ$O5a$a$i$l$F$-$^$7$?!#e(B
e$B$7$+$7!"BP>[email protected][email protected]$1$G$O:,5r$,<e$/!"F~$k$3$H$J$/:#$K;j$C$F$$$^$9!#e(B

e$B:#2s$O!"e(BString#split e$B$N=P8=IQEY$rD4$Y$F$$^$7$?!#e(B
Rubye$B$N%=!<%9$GD4$Y$F$
$k$H!"e(B
% grep split **/.rb|wc -l
1096
% grep gsub **/
.rb|wc -l
617
% grep push **/.rb|wc -l
732
% grep to_i **/
.rb|wc -l
1034
% grep to_s **/.rb|wc -l
2414
% grep each **/
.rb|wc -l
4752
e$B$H$$$&7k2L$NDL$j!"e(Beach e$B$de(B to_s e$B$K$OIi$1$k$b$N$N!"e(Bto_i
e$B$KJB$S!"e(B
e$B9b=g0L$,M=A[$5$l$?e(B gsub e$B$r$b1[$($k;HMQIQEY$r8X$C$F$$$^$9!#e(B

[email protected]$1$NIQEY$J$i$Pe(B /
e$B$r3d$jEv$F$k$KB-$H;W$&$N$G$9$,!"$$$+$,$G$7$g$&$+!#e(B
e$B$b$72?$+$Ke(B String#/ e$B$r$"$F$k$J$i$P!"e(BString#split
[email protected]$ODc$$$h$&$K;W$$$^$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:39203] [Feature #2017] String#/(sep)”
on Mon, 31 Aug 2009 02:35:51 +0900, Yui NARUSE
[email protected] writes:

|e$B0JA0$+$i!"e(BArray#(sep) e$B$H$NBP>[email protected]$+$ie(B String#/(sep) e$B$N:NMQ$O5a$a$i$l$F$-$^$7$?!#e(B
|e$B$7$+$7!"BP>[email protected][email protected]$1$G$O:,5r$,<e$/!"F~$k$3$H$J$/:#$K;j$C$F$$$^$9!#e(B
|
|e$B:#2s$O!"e(BString#split e$B$N=P8=IQEY$rD4$Y$F$$^$7$?!#e(B
|Rubye$B$N%=!<%9$GD4$Y$F$
$k$H!"e(B
|% grep split **/
.rb|wc -l
| 1096

String#/e$B$Oe(B str.split(sep) e$B$N7A<[email protected]$1?t$($k$Y$-$G$O$J$$e(B
e$B$G$7$g$&$+!#$b$A$m$s!“e(Bstr / “” e$B$G$bI=8=2DG=$G$7$g$&$,!”$"$^e(B
e$B$j0U?^$rI=8=$7$F$$$k$H$O;W$($^$;$s$+$i!#e(B

|[email protected]$1$NIQEY$J$i$Pe(B / e$B$r3d$jEv$F$k$KB-$H;W$&$N$G$9$,!"$$$+$,$G$7$g$&$+!#e(B
|e$B$b$72?$+$Ke(B String#/ e$B$r$"$F$k$J$i$P!"e(BString#split [email protected]$ODc$$$h$&$K;W$$$^$9!#e(B

e$B$=$l$OG’$a$^$9!#e(B

e$B%A%1%C%He(B #2017 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

String#/e$B$Oe(B str.split(sep) e$B$N7A<[email protected]$1?t$($k$Y$-$G$O$J$$e(B
e$B$G$7$g$&$+!#$b$A$m$s!“e(Bstr / “” e$B$G$bI=8=2DG=$G$7$g$&$,!”$"$^e(B
e$B$j0U?^$rI=8=$7$F$$$k$H$O;W$($^$;$s$+$i!#e(B

e$B$U$`!"$J$k$[$I!#e(B.e$B$He(B(e$B$rF~$l$Fe(Bgrepe$B$9$k$h$&$K$7$F$_$^$7$?!#e(B
% grep ‘.split(’ **/.rb|wc -l
430
% grep ‘.gsub(’ **/
.rb|wc -l
404
% grep ‘.unpack(’ **/.rb|wc -l
344
% grep ‘.unpack(’ **/
.rb|wc -l
344
% grep ‘.sub(’ **/*.rb|wc -l
640

e$B9g$o$;$Fe(B Google Code Search e$B$GD4$Y$F$_$k$H!"e(B
lang:ruby .split( e$BLse(B68,300e$B7oe(B
lang:ruby .gsub( e$BLse(B55,800e$B7oe(B
lang:ruby .gsub( e$BLse(B24,800e$B7oe(B
lang:ruby .unpack( e$BLse(B8,000e$B7oe(B

e$B$J$*!"<B:]$K$Oe(B String#split(sep, count)
e$B$rH4$+$J$$$H$$$1$J$$$N$G!"e(B
e$B2>$K!"e(Blang:ruby .split([^,)]+)
e$B$H$9$k$H!"Lse(B59,200e$B7o$G$7$?!#e(B

http://redmine.ruby-lang.org/issues/show/2017

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:39208] [Feature #2017] String#/(sep)”
on Mon, 31 Aug 2009 20:25:40 +0900, Yui NARUSE
[email protected] writes:

|> String#/e$B$Oe(B str.split(sep) e$B$N7A<[email protected]$1?t$($k$Y$-$G$O$J$$e(B
|> e$B$G$7$g$&$+!#$b$A$m$s!“e(Bstr / “” e$B$G$bI=8=2DG=$G$7$g$&$,!”$"$^e(B
|> e$B$j0U?^$rI=8=$7$F$$$k$H$O;W$($^$;$s$+$i!#e(B
|
|e$B$U$`!"$J$k$[$I!#e(B.e$B$He(B(e$B$rF~$l$Fe(Bgrepe$B$9$k$h$&$K$7$F$_$^$7$?!#e(B
|% grep ‘.split(’ **/.rb|wc -l
| 430
|% grep ‘.gsub(’ **/
.rb|wc -l
| 404
|% grep ‘.unpack(’ **/.rb|wc -l
| 344
|% grep ‘.unpack(’ **/
.rb|wc -l
| 344
|% grep ‘.sub(’ **/*.rb|wc -l
| 640

e$B$$$d$$$d!"e(Bgsube$B$=$NB>$O3g8L$OF~$l$J$$$G?t$($J$$$H!#e(B
e$BA02s$N?t;z$HAH$_9g$o$;$k$3$&$J$j$^$9!#e(B

% grep each **/*.rb|wc -l
4752

e$B:#2s?t$($?$b$N$NCf$G$O:G>/$H$$$&$3$H$K$J$j$^$9$M!#e(B
e$B$$$:$l$K$7$F$b$=$l$J$j$K$O<{MW$O$"$k$H$$$&$3$H$OG’$a$^$9!#e(B

e$B%A%1%C%He(B #2017 e$B$,99?7$5$l$^$7$?!#e(B (by Run Paint Run R.)

I don’t object to this proposal, but note that it leads to unfortunate
syntax when sep is a /-delimited regex. For example:

‘f o o’ / / /
=> [“f”, “o”, “o”]

Even adding the optional parentheses doesn’t help readability. Short of
simply recommending people don’t write ugly code, a compromise could be
for String#/ to only accept String separators. (Of course if this
concern has already been addressed, then I apologise in advance for
intruding).

http://redmine.ruby-lang.org/issues/show/2017

[email protected]@%$G$9!#e(B

Yukihiro M. wrote:

e$B:#2s?t$($?$b$N$NCf$G$O:G>/$H$$$&$3$H$K$J$j$^$9$M!#e(B
e$B$$$:$l$K$7$F$b$=$l$J$j$K$O<{MW$O$"$k$H$$$&$3$H$OG’$a$^$9!#e(B

String e$B$NCf$G$bFC$K?t$NB?$=$&$J$b$N$rA*$s$G5s$2$F$$$^$9$+$i$M!#e(B
e$B$^$!!"[email protected]$O$3$l0J>e=R$Y$kI,MW$O$J$$$H;W$$$^$9!#e(B

e$B$D$^$je(B String#/ e$B$O!"e(B

  • alias e$B85$G$"$ke(B String#split e$B$O==J,$K;H$o$l$F$$$ke(B
    e$B"*e(B 1e$BJ8;z%a%=%C%[email protected]$k;q3J$,$"$ke(B
  • String#/ e$B$Ne(B alias
    e$B858uJd$K5s$,$j$=$&$JJL$N%a%=%C%I$O8+Ev$?$i$J$$e(B
    e$B"*e(B [email protected]$ODc$$e(B
    e$B$^$G$O>/$J$/$H$bK~$?$7$F$$$k$o$1$G$9!#e(B

e$B$G!";W$&$K$R$C$+$+$C$F$$$k$N$ODI2C$5$l$FC/$,$&$l$7$$$N!)e(B
e$B$H$$$&[email protected]$H;W$&$N$G$9$,!"Nc$($Pe(B
http://jarp.does.notwork.org/diary/200909a.html#200909012
e$B$N?M$H$+$O$$$$$H$7$F!"e(B

e$B$o$?$7$,$[$7$$$H;W$C$?$N$O!“0J2<$N$h$&$J>l9g$G$7$g$&$+!#e(B
IO.readlines(“some.txt”).map{|l|l.chomp!}.map{|l| l.split(”,") }
IO.readlines(“some.txt”).map{|l|l.chomp!}.map{|l| l.split “,” }
IO.readlines(“some.txt”).map{|l|l.chomp!}.map{|l| l / “,” }
e$B:[email protected]$H$+$C$3$,L\N)$A!"$+$H$$$C$F$J$$$N$bMn$ACe$+$:!"e(B
e$B;[email protected]$H%7%s%W%k$K$^$H$^$k$h$&$K8+$($^$9!#e(B

Run Paint Run R. e$B$5$s$N6D$kDL$j!"e(B
e$B$^$?$^$D$b$H$5$s$,$*$=$i$/7|G0$J$5$C$F$$$kDL$j!"e(B
e$B8+$E$i$/=q$/J}K!$,A}$($k$H$$$&$N$O3N$+$K$=$&$J$s$G$9$,!"e(B
e$B$3$l$,$J$/$F$b$9$G$K$=$&$$$C$?%3!<%I$O=q$1$k$o$1$G!"e(B
e$B$=$l$r7|G0$9$k$h$j$O<B:]$N;H$$J,$1$O8D!9?M$K0Q$M$?J}$,e(B
e$B$h$$$N$G$O$J$$$+$H;W$C$F$$$^$9!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs