e$B@>;3OB9-$G$9!#e(B
Enumerable#cyclee$B$Ne(Brdoce$BItJ,$Ne(Ba.eache$B$Oe(Ba.cyclee$B$Ne(Btypoe$B$G$O$J$$$G$7$g$&$+e(B?
Index: enum.c
— enum.c (revision 12907)
+++ enum.c (working copy)
@@ -1546,7 +1546,7 @@
- forever. Enumerable#cycle saves elements in an internal array.
-
-
a = ["a", "b", "c"]
-
-
a.each {|x| puts x } # print, a, b, c, a, b, c,.. forever.
-
-
a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
-
*/
Enumerable#cyclee$B$,FMA3DI2C$5$l$?$h$&$K8+$($k$N$GM}M3$,5$$K$J$j$^$7$?!#e(B
e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:31362] typo in enum.c”
on Thu, 9 Aug 2007 00:40:24 +0900, Kazuhiro NISHIYAMA
[email protected] writes:
|Enumerable#cyclee$B$Ne(Brdoce$BItJ,$Ne(Ba.eache$B$Oe(Ba.cyclee$B$Ne(Btypoe$B$G$O$J$$$G$7$g$&$+e(B?
e$B$G$9$M!#e(BRDoce$B$r%3%T!<$7$F$-$?;~$K=$@5$7K:$l$F$^$7$?!#e(B
|# Enumerable#cyclee$B$,FMA3DI2C$5$l$?$h$&$K8+$($k$N$GM}M3$,5$$K$J$j$^$7$?!#e(B
e$B$$$d!"e(Bcyclee$B;H$C$Fe(BFizzBazze$B<BAu$7$F$k$N$r8+$+$1$F$&$i$d$^$7$/$J$Ce(B
e$B$?$@$1$G$9!#e(B
e$B$J$+$@$G$9!#e(B
At Thu, 9 Aug 2007 02:07:54 +0900,
Yukihiro M. wrote in [ruby-dev:31364]:
|# Enumerable#cyclee$B$,FMA3DI2C$5$l$?$h$&$K8+$($k$N$GM}M3$,5$$K$J$j$^$7$?!#e(B
e$B$$$d!"e(Bcyclee$B;H$C$Fe(BFizzBazze$B<BAu$7$F$k$N$r8+$+$1$F$&$i$d$^$7$/$J$Ce(B
e$B$?$@$1$G$9!#e(B
e$B$8$c$D$$$G$Ke(BString#nonempty?e$B$b$$$l$^$9$+e(B?
$ ./ruby -e ‘n3, n5 = ([""]*2<<“fizz”).cycle, ([""]*4<<“buzz”).cycle
1.upto(100){|i|puts “#{n3.next}#{n5.next}”.nonempty?||i}’
sub(/\A\z/){i} e$B$G$b$G$-$^$9$1$I$M!#e(B
Index: string.c
— string.c (revision 12905)
+++ string.c (working copy)
@@ -425,4 +425,22 @@ rb_str_empty(VALUE str)
}
+/*
-
-
-
-
- Returns
self
if str is not empty, or
nil
.
-
-
-
- */
-
+static VALUE
+rb_str_nonempty(VALUE str)
+{
- if (RSTRING_LEN(str) == 0)
- return Qnil;
- return str;
+}
-
/*
- call-seq:
@@ -4828,4 +4846,10 @@ sym_empty(VALUE sym)
}
+static VALUE
+sym_nonempty(VALUE sym)
+{
- return rb_str_nonempty(rb_id2str(SYM2ID(sym)));
+}
-
static VALUE
sym_upcase(VALUE sym)
@@ -4911,4 +4935,5 @@ Init_String(void)
rb_define_method(rb_cString, “size”, rb_str_length, 0);
rb_define_method(rb_cString, “empty?”, rb_str_empty, 0);
- rb_define_method(rb_cString, “nonempty?”, rb_str_nonempty, 0);
rb_define_method(rb_cString, “=~”, rb_str_match, 1);
rb_define_method(rb_cString, “match”, rb_str_match_m, -1);
@@ -5038,4 +5063,5 @@ Init_String(void)
rb_define_method(rb_cSymbol, “size”, sym_length, 0);
rb_define_method(rb_cSymbol, “empty?”, sym_empty, 0);
- rb_define_method(rb_cSymbol, “nonempty?”, sym_nonempty, 0);
rb_define_method(rb_cSymbol, “match”, sym_match, -1);
e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:31365] Re: typo in enum.c”
on Thu, 9 Aug 2007 03:00:02 +0900, Nobuyoshi N.
[email protected] writes:
|> e$B$$$d!"e(Bcyclee$B;H$C$Fe(BFizzBazze$B<BAu$7$F$k$N$r8+$+$1$F$&$i$d$^$7$/$J$Ce(B
|> e$B$?$@$1$G$9!#e(B
|
|e$B$8$c$D$$$G$Ke(BString#nonempty?e$B$b$$$l$^$9$+e(B?
e$B$=$l$O%$%d!#$J$s$H$J$/!#$?$V$s!"L>A0$,!#e(B