From: AW Date: 2002-08-21T09:11:16+09:00 Subject: Re: the power of ruby Wow, Doing it that way had never accured to me. How does that work that you can use dot notation from a bracket '}' ? I keep looking at the last line and I cant seem to grasp its relationship, I mean, If the first set of '{}' are containing the loop from the '.times' method, how do the second set relate? Now i'm really confused. Thank you! ;-) >Yours is rather succinct, but I find that you can often capitalize >on return values of methods to shorten. Shorten, right? You're >looking for shorter? Im looking for exactly what you gave. different ways to express the same output in Ruby. Shorter, longer, obsfucated, clear. I just hope others will chime in and give some examples of their own style. > >Here's one: > > WIDTH = 78 > def do_dot( i ) > puts( ( " " * i ) + "*" ) > end > loop { > WIDTH.times { |i| do_dot(i) }.downto(0) { |i| do_dot(i) } > } > >Check ya later. > >_why > >AW (sturmpanzer@metacrawler.com) wrote: >> >> Here is my unimaginitive attempt. >> >> [code]============================================== >> WIDTH=78; >> def do_dot(i) >> i.times{print " "} >> puts "*"; >> end >> loop{ >> 0.upto(WIDTH-1){|i| >> do_dot(i); >> } >> WIDTH.downto(1){|i| >> do_dot(i); >> } >> } >> [/code]============================================= >