From: coolgeng coolgeng Date: 2008-03-06T18:08:06+09:00 Subject: Re: Erratic result ------=_Part_5390_5714050.1204794494385 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Yeah, it does work. But I really want to know what does it happen? such as "puts digits.each {|digit| dial(digit) }" or "digits.each {|digit| dial(digit) }" the former will print the digits value at the last line,but the latter will not On Thu, Mar 6, 2008 at 5:01 PM, Jes=FAs Gabriel y Gal=E1n < jgabrielygalan@gmail.com> wrote: > On Thu, Mar 6, 2008 at 9:49 AM, coolgeng coolgeng > wrote: > > Hi > > I do not know how to explain the different result between the two > > snippets: > > First snippet: > > def dial(digit) > > puts digit end > > digits =3D 0..9 > > puts digits.each {|digit| dial(digit) } > > > Why did the first snippet will generate the word like "0..9" at last > line? > > Because you are calling puts with the result of the each method, which > in this is the range. > Take into account that .each will run the block yielding each element, > and then will return something. > You can remove the last puts: > > def dial(digit) > puts digit > end > digits =3D 0..9 > digits.each {|digit| dial(digit) } > > Jesus. > > --=20 Best Regards Cooper Geng ------=_Part_5390_5714050.1204794494385--