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K%Q%C%A$r;}$C$F$$$^$9!#e(B

e$B$=$l$G$O!#e(B


#2

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

In message “Re: [ruby-dev:38493] [Feature:trunk] enhancement of
Array#drop”
on Tue, 19 May 2009 15:58:46 +0900, “U.Nakamura”
removed_email_address@domain.invalid writes:

|Rubye$B$G%9%/%j%W%H$r=q$$$F$$$F!“G[Ns$+$i!”$"$k>r7o$K9gCW$9$k@he(B
|e$BF,$NMWAG$N$$r:o=|$9$k!"$H$$$&=hM}$r=q$-$?$$>lLL$K=P2q$C$?$3e(B
|e$B$H$,2?EY$+$"$j$^$9!#e(B
|
|e$BL5>r7o$G@hF,$NMWAG$r:o=|$9$k%a%=%C%I$H$7$F$Oe(Bshifte$B$^$?$Oe(Bdrop(1)
|e$B$,$"$j!"$^$?!">r7o$K9gCW$7$?A4$F$NMWAG$r:o=|$9$k%a%=%C%I$H$7e(B
|e$B$F$Oe(Bdeletee$B$,$"$j$^$9$,!"$"$k>r7o$K9gCW$9$k@hF,$NMWAG$N$
$r:oe(B
|e$B=|$7$h$&$H$9$k$H!“0U30$HJ#;($J5-=R$K$J$C$F$7$^$$$^$9!#e(B
|
|… e$B$H$$$&OC$re(BIRCe$B$G$7$F$_$?$H$3$m!”$J$+$@$5$s$K!Ve(Bdrope$B$K%V%m%Ce(B
|e$B%/0z?t$rDI2C$9$k$N$O$I$&$+!W$H8@$o$l$^$7$?!#e(B

drop_whilee$B$H$O0c$&$N$G$9$M!#e(B

|e$B;d$H$7$F$O$3$N;EMM$,<B8=$5$l$k$HBgJQJXMx$H;W$&$N$G$9$,!"$$$+e(B
|e$B$,$G$7$g$&$+!#e(B

drop_whilee$B$K@hF,$$$/$D$^$G$H$$$&0z?t$rDI2C$9$k$H$$$&9M$(J}$be(B
e$B$"$j$^$9$M!#$?$@$7!"$3$N>l9g$Oe(B

|e$B$5$i$K!"Bhe(B2e$B0z?t$,;XDj$5$l$?>l9g$O!“e(B{|e| e === e$BBhe(B2e$B0z?te(B} e$B$H$_$Je(B
|e$B$9$h$&$K$9$l$P$5$i$KJXMx!”$H$b8@$o$l$^$7$?!#e(B

e$B$,<+A3$K<B8=$G$-$^$;$s$,!#e(B


#3

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:38495] Re: [Feature:trunk] enhancement of
Array#drop”
on May.19,2009 16:20:07, removed_email_address@domain.invalid wrote:
| |Rubye$B$G%9%/%j%W%H$r=q$$$F$$$F!“G[Ns$+$i!”$"$k>r7o$K9gCW$9$k@he(B
| |e$BF,$NMWAG$N$$r:o=|$9$k!"$H$$$&=hM}$r=q$-$?$$>lLL$K=P2q$C$?$3e(B
| |e$B$H$,2?EY$+$"$j$^$9!#e(B
| |
| |e$BL5>r7o$G@hF,$NMWAG$r:o=|$9$k%a%=%C%I$H$7$F$Oe(Bshifte$B$^$?$Oe(Bdrop(1)
| |e$B$,$"$j!"$^$?!">r7o$K9gCW$7$?A4$F$NMWAG$r:o=|$9$k%a%=%C%I$H$7e(B
| |e$B$F$Oe(Bdeletee$B$,$"$j$^$9$,!"$"$k>r7o$K9gCW$9$k@hF,$NMWAG$N$
$r:oe(B
| |e$B=|$7$h$&$H$9$k$H!“0U30$HJ#;($J5-=R$K$J$C$F$7$^$$$^$9!#e(B
| |
| |… e$B$H$$$&OC$re(BIRCe$B$G$7$F$_$?$H$3$m!”$J$+$@$5$s$K!Ve(Bdrope$B$K%V%m%Ce(B
| |e$B%/0z?t$rDI2C$9$k$N$O$I$&$+!W$H8@$o$l$^$7$?!#e(B
|
| drop_whilee$B$H$O0c$&$N$G$9$M!#e(B

e$B;d$,40c$$$7$F$J$1$l$P!“e(Bdrop_whilee$B$O!V$”$k>r7o$K9gCW$9$kMWAGe(B
e$B$h$jA0$NMWAG$rA4$F:o=|$9$k!W$G$9$+$i!";d$,M_$7$$J
$H$O0c$&$he(B
e$B$&$G$9!#e(B
e$BLa$jCM$dBP>]L$H/8+;~$NNc30$NM-L5$J$I$rL5;k$9$l$P!";d$,M_$7$$e(B
e$BJ*$Oe(B ary.delete_at(ary.index(elem)) e$B$H=q$1$^$9!#e(B

e$B$=$l$G$O!#e(B


#4

In article removed_email_address@domain.invalid,
Yukihiro M. removed_email_address@domain.invalid writes:

[:a, :b, :a, :b].drop(1){|e| e == :b} #=> [:a, :a, :b]
[:a, :b, :a, :b].drop(2){|e| e == :b} #=> [:a, :a]

e$B$@$=$&$G$9$+$i!"$3$l$O!V0z?t$G;XDj$7$?HO0OFb$G>r7o$rK~$?$9MWe(B
e$BAG$r:o=|$9$k!W%a%=%C%I$K$J$C$F$$$^$9!#$&$5$5$s$N$[$7$$$b$N$Oe(B
e$B$3$C$A$J$s$G$9$+!)e(B

e$B$3$l$O!"e(B

drop one element which equals :b
drop two elements which equals :b

e$B$HFI$`$s$8$c$J$$$G$9$+$M$’!#e(B

e$B$*$=$i$/!#e(B


#5

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

In message “Re: [ruby-dev:38500] Re: [Feature:trunk] enhancement of
Array#drop”
on Wed, 20 May 2009 00:06:19 +0900, “U.Nakamura”
removed_email_address@domain.invalid writes:

|| drop_whilee$B$H$O0c$&$N$G$9$M!#e(B
|
|e$B;d$,40c$$$7$F$J$1$l$P!“e(Bdrop_whilee$B$O!V$”$k>r7o$K9gCW$9$kMWAGe(B
|e$B$h$jA0$NMWAG$rA4$F:o=|$9$k!W$G$9$+$i!";d$,M_$7$$J
$H$O0c$&$he(B
|e$B$&$G$9!#e(B

e$B0c$$$^$9!#e(Bdrop_whilee$B$O!V$"$k>r7o$K9gCW$9$k4V!"MWAG$r@hF,$+$ie(B
e$B:o=|$9$k!W$G$9!#e(BRDoce$B$+$iNcBj$r0zMQ$9$k$He(B

a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 }   # => [3, 4, 5, 0]

e$B$G$9!#$3$l$O!"$&$5$5$s$,:G=i$K=q$$$?e(B

Rubye$B$G%9%/%j%W%H$r=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%A$NF3F~$O;?@.$7$^$;$s!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

#6

e$B%A%1%C%He(B #1492 e$B$,99?7$5$l$^$7$?!#e(B (by Yukihiro M.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

redundant

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


#7

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

In message “Re: [ruby-dev:38505] Re: [Feature:trunk] enhancement of
Array#drop”
on Wed, 20 May 2009 01:19:11 +0900, Tanaka A. removed_email_address@domain.invalid
writes:

|>> [:a, :b, :a, :b].drop(1){|e| e == :b} #=> [:a, :a, :b]
|>> [:a, :b, :a, :b].drop(2){|e| e == :b} #=> [:a, :a]
|>
|> e$B$@$=$&$G$9$+$i!"$3$l$O!V0z?t$G;XDj$7$?HO0OFb$G>r7o$rK~$?$9MWe(B
|> e$BAG$r:o=|$9$k!W%a%=%C%I$K$J$C$F$$$^$9!#$&$5$5$s$N$[$7$$$b$N$Oe(B
|> e$B$3$C$A$J$s$G$9$+!)e(B
|
|e$B$3$l$O!"e(B
|
| drop one element which equals :b
| drop two elements which equals :b
|
|e$B$HFI$`$s$8$c$J$$$G$9$+$M$’!#e(B

e$B$$!#$=$s$JFI$_J}$,!#e(B

e$B$=$C$A$NJ}$,0UL#$O$"$j$=$&$G$9$M!#$"$s$^$j;?@.$8$c$J$$$N$OJQe(B
e$B$o$i$J$$$s$G$9$,!#e(B