From: "David A. Black" Date: 2005-08-11T05:26:56+09:00 Subject: Re: anonym variable $_ and foreach similar in Ruby ? --8323328-821250688-1123705613=:16164 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-821250688-1123705613=:16164" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-821250688-1123705613=:16164 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Thu, 11 Aug 2005, [ISO-8859-1] Florian Gro=DF wrote: > James Edward Gray II wrote: > >>> In perl >>> print $_, "\n" foreach (@array); >>> Are there other ways than those two array.each? >>=20 >> Or: >>=20 >> array.each { |e| puts e } >>=20 >> Or just: >>=20 >> puts array >>=20 >> I like that better than Perl, but you decide... ;) > > And the general form for guys who are too lazy to pass along arguments: > > [1, 2, 3].each(&method(:puts)) > > But I think ary.each { |e| puts e } is the Ruby way. I don't; I advocate doing puts ary and let Ruby do the work :-) I know, I know... it's not as explicit in its handling of each element. But once someone tells you how it works, you know; and I think learning that is one of the Ruby rites of passage (like learning that #{...} interpolates more than variables :-) David --=20 David A. Black dblack@wobblini.net --8323328-821250688-1123705613=:16164-- --8323328-821250688-1123705613=:16164--