Etc.passwd の挙動について

xibbar$B$3$HF#2,$G$9!#(B

Etc.passwd $B$r;H$C$F$_$F!“LL?)$i$C$?$N$GMWK>$r=P$7$F$*$-$^$9!#(B
$B8=>u$O!”(B

irb(main):028:0* Etc.passwd
=> #<struct Struct::Passwd name="_calendar", passwd="*", uid=93, gid=93,
gecos=“Calendar”, dir="/var/empty", shell="/usr/bin/false", change=0,
uclass="", expire=0>

irb(main):029:0> Etc.passwd
=> #<struct Struct::Passwd name="_ces", passwd="*", uid=32, gid=32,
gecos=“Certificate Enrollment Service”, dir="/var/empty",
shell="/usr/bin/false", change=0, uclass="", expire=0>

$B$C$F46$8$G!"(B/etc/passwd $B$r(B1$B9T$:$DFI$_9~$s$G!"(B
Struct$B$GJV$9;EMM$K$J$C$F$$$^$9!#(B
$B%V%m%C%/$rM?$($k$H!"(B

irb(main):034:0* Etc.passwd{|pw|p pw}
#<struct Struct::Passwd name="_amavisd", passwd="", uid=83, gid=83,
gecos=“AMaViS Daemon”, dir="/var/virusmails", shell="/usr/bin/false",
change=0, uclass="", expire=0>
#<struct Struct::Passwd name="_appleevents", passwd="
", uid=55, gid=55,
gecos=“AppleEvents Daemon”, dir="/var/empty", shell="/usr/bin/false",
change=0, uclass="", expire=0>

$B$C$F46$8$G!"(B1$B9T$:$DFI$9~$s$G2?$+$G$-$kMM$K$J$C$F$$$^$9!#(B
$B$3$l$,!"(BRuby$BE*$K$O(B
Etc.passwd.each{|pw|p pw}
$B$H$+$C$F$d$l$?$[$&$,6C$-$,>/$J$$$H;W$C$?$N$G$9$,(B
$B$$$+$,$G$7$g$&$+!#(B
$B>/$J$/$H$b(B Etc.passwd
$B$G(B1$B9T$:$DFI$
[email protected]$7$?(BStruct$B$,JV$C$F$/$k$h$j$b(B
$B$$$$$+$J$H;W$$$^$9!#(B

Etc.passwd.to_a $B$H$+=PMh$?$[$&$,$$$$$N$G$O$J$$$+$H;W$$$^$9!#(B
$B8=>u!"(BStruct$B$N(BArray$B$r:n$kJ}K!$b$J$/$F!"(B
pw_ary=[]
Etc.passwd{|pw|pw_ary << pw}
$B$H$+$d$i$J$-$c$J$i$J$$$G$9!#(B

$B$I$&$$$&;EMM$K$7$?$i%9%^!<%H$+$H$$$&$"$?$j$^$G$O(B
$BF’$9~$a$F$$$^$;$s$,!"$H$j$"$($:LL?)$i$C$?$N$G(B
$BITK~$r=q$$$F$
$^$7$?!#(B

$B$h$m$7$/$*4j$$$7$^$9!#(B

$BF#2,$G$9!#(B

IRC$B$GCfED$5$s$K(BEtc::Passwd$B$r;H$([email protected]$o$l$F$7$^$$!"(B
$B$3$C$A$K%S%C%/%j$8$c$J$$;EMM$N$b$N$,$"$j$^$7$?!#(B

$B$3$l$r;H$&$3$H$K$7$^$9!#(B
Etc$B$N%b%8%e!<%k$N$[$&$O$"$^$j;H$o$J$$$3$H$K$7$F$*$-$^$9!#(B

At Fri, 12 Apr 2013 23:39:17 +0900,
fujioka wrote:

Etc.passwd.to_a $B$H$+=PMh$?$[$&$,$$$$$N$G$O$J$$$+$H;W$$$^$9!#(B
$B8=>u!"(BStruct$B$N(BArray$B$r:n$kJ}K!$b$J$/$F!"(B
pw_ary=[]
Etc.passwd{|pw|pw_ary << pw}
$B$H$+$d$i$J$-$c$J$i$J$$$G$9!#(B

$B0l1~!"(B

Etc.to_enum(:passwd).to_a

$B$H$$$&<j$O$"$j$^$9!#%V%m%C%/$J$7$NJ}$O0l2s:G8e$^[email protected]$k$H(B rewind
$B$9(B
$B$k<jN)$F$,$J$$$N$G%@%a$G$9$M!#(B

[email protected]>;3OB9-$G$9!#(B

At Mon, 15 Apr 2013 13:34:15 +0900,
Akinori MUSHA wrote:

$B0l1~!"(B

Etc.to_enum(:passwd).to_a

$B$H$$$&<j$O$"$j$^$9!#%V%m%C%/$J$7$NJ}$O0l2s:G8e$^[email protected]$k$H(B rewind $B$9(B
$B$k<jN)$F$,$J$$$N$G%@%a$G$9$M!#(B

Enumerator $B$NJ}$b:G8e$^$G$h$s$G$$$J$$$b$N$,$"$k$H!"(B
$B$h$a$J$/$J$C$F:$$C$?$3$H$K$J$k$h$&$G$9!#(B

% cat x.rb
require ‘etc’
p Etc.to_enum(:passwd).next
p Etc.to_enum(:passwd).next
% ruby -v x.rb
ruby 2.1.0dev (2013-04-21 trunk 40403) [x86_64-linux]
#<struct Etc::Passwd name=“root”, passwd=“x”, uid=0, gid=0,
gecos=“root”, dir="/root", shell="/bin/bash">
x.rb:3:in next': parallel passwd iteration (RuntimeError) from x.rb:3:in
%