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$5$l$F$$$k$+$I$&$+$H$+!"%Q%i%0%i%U$@$C$?$ie(B
e$B6u9T$+$I$&$+$H$+!"8D!9$NMWAG$rJ,N$9$k$H$3$m$OLdBj$K$h$C$F0[e(B e$B$J$k$N$G$9$,!"$=$N8e$NJ,N
7k2L$K$7$?$,$C$FO"B3$7$?MWAG$r$^$H$ae(B
e$B$k$N$O6&DL$7$F$$$k$N$G!“e(BEnumerable e$B$K%a%=%C%I$H$7$F$”$C$F$be(B
e$B$$$$$s$8$c$J$$$+$H;W$$$^$9!#e(B
e$B$H$$$&$o$1$G!“e(BEnumerable#gather_each(arg) {|ary| … } e$B$NDse(B
e$B0F$G$9!#0z?t$K$Oe(B Proc e$B$rM?$($F!”$3$l$O3FMWAG$K$D$$$F8F$P$l!"e(B
e$B7k2L$H$7$FJ,N7k2L$rJV$7$^$9!#e(Bgather_each e$B$O$=$NJ,N
7k2L$,Eye(B
e$B$7$$O"B3$7$?MWAG$rG[Ns$H$7$F$^$H$a$Fe(B yield e$B$7$^$9!#e(B
e$B$J$*!“J,N`7k2L$,e(B nil e$B$H$$$&$N$OFCJL07$$$G!”$=$NMWAG$OC1FH$Ge(B
e$B$^$H$^$j$H$J$k$3$H$r<($7$^$9!#e(B
Ruby e$B$G$N<BAu$r0J2<$K<($7$^$9!#e(B
module Enumerable
def gather_each(arg)
prev_value = prev_elts = nil
self.each {|e|
v = arg.call(e)
if prev_value == nil
if v == nil
yield [e]
else
prev_value = v
prev_elts = [e]
end
else
if v == nil
yield prev_elts
yield [e]
prev_value = prev_elts = nil
elsif prev_value == v
prev_elts << e
else
yield prev_elts
prev_value = v
prev_elts = [e]
end
end
}
if prev_value != nil
yield prev_elts
end
end
end
e$B$?$H$($P!"e(Blib/scanf.rb e$B$K$Oe(B RD
e$B$J%I%-%e%a%s%H$,F~$C$F$$$F!"e(B
e$B0J2<$N$h$&$K$9$k$H%$%s%G%s%H$5$l$?%3!<%INc$NItJ,$r$R$H$D$K$^e(B
e$B$H$a$k$3$H$,$G$-$^$9!#e(B
arg = lambda {|l| /\A=~ l ? true : nil }
open(“lib/scanf.rb”) {|f|
f.gather_each(arg) {|lines| pp lines }
}
=>
["# scanf for Ruby\n"]
["#\n"]
["# $Release Version: 1.1.2 $\n"]
…
[“the return array (or yielded to the block, if a block was
given).\n”]
["\n", “\n”]
["==Basic usage\n"]
["\n",
" require ‘scanf.rb’\n",
“\n”,
" # String#scanf and IO#scanf take a single argument (a
format string)\n",
" array = aString.scanf("%d%s")\n",
" array = anIO.scanf("%d%s")\n",
“\n”,
" # Kernel#scanf reads from STDIN\n",
" array = scanf("%d%s")\n",
“\n”]
["==Block usage\n"]
["\n"]
…
e$B%Q%i%0%i%U%b!<%I$C$]$/!"6u9T$G6h@Z$i$l$?ItJ,$r$^$H$a$?$$$J$ie(B
e$B0J2<$N$h$&$K$G$-$^$9!#e(B
arg = lambda {|l| l == “\n” }
open(“lib/scanf.rb”) {|f|
f.gather_each(arg) {|lines| pp lines }
}
=>
["# scanf for Ruby\n",
“#\n”,
“# $Release Version: 1.1.2 $\n”,
“# $Revision: 22784 $\n”,
“# $Id: scanf.rb 22784 2009-03-06 03:56:38Z nobu $\n”,
“# $Author: nobu $\n”,
“#\n”,
“# A product of the Austin Ruby Codefest (Austin, Texas,
August 2002)\n”]
["\n"]
["=begin\n"]
["\n"]
["=scanf for Ruby\n"]
["\n"]
["==Description\n"]
["\n"]
[“scanf for Ruby is an implementation of the C function
scanf(3),\n”,
“modified as necessary for Ruby compatibility.\n”]
["\n"]
…
e$B$I$&$G$7$g$&e(B?
e$B$J$*!“J#?t9T$r$^$H$a$kJ}K!$H$7$F;H$$$=$&$J$b$N$O!”$^$H$a$k@he(B
e$BF,MWAG$r8!=P$9$kJ}K!$r;XDj$9$k$H$+!“B>$K$b$$$/$D$+$”$k$h$&$Ke(B
e$B;W$$$^$9!#$?$H$($Pe(B ChangeLog e$B$de(B mbox
e$B$r07$&$N$K$O!"@hF,MWAGe(B
e$B$r;XDj$9$k$N$,$$$$$G$7$g$&!#$=$&$$$&$b$N$O$^$?JL$N%a%=%C%I$He(B
e$B$7$F:n$k$N$,$$$$$N$G$O$J$$$+$H;W$$$^$9!#e(B