Michael Brooks
2/23/2007 7:50:00 AM
KCons wrote:
> I'm sure there is some far superior prior art out there somewhere, but
> this is a useful little hack I threw together today that I thought
> someone else might find interesting.
>
> I wanted to do a little task every few seconds for some duration of
> time, and after a bit of overkill I came up with a little library that
> lets me do stuff like:
>
> every( 5.seconds ).for( 2.days ) { puts "Chunky bacon, k?" }
>
> or
>
> every( 2.minutes ).until ( Time.now + 4.hours ) { dance_for_a_while }
>
> or even
>
> class String
> def gradual_out( n = 1 )
> ix = 0
> every( n.seconds ).unless(lambda {ix >= size}) do
> print self[ix].chr
> ix += 1
> end
> end
> end
>
> "Tuesday is the new Thursday".gradual_out( 400.milliseconds )
>
>
> Fun to play with.
> Again, just a quick hack, so if you see any glaring issues or useful
> improvements, let me know, because I'm sure I'll find use for it again
> later.
>
<snip>
Hello KCons:
Wow... I'm just (8 hours into both) learning Python and Ruby and I
didn't realize how powerful / extensible Ruby was until I saw your
example. Great stuff!
Thanks,
Michael