From: "David A. Black" Date: 2008-09-07T04:46:57+09:00 Subject: Re: Request for Block local methods, and Proc syntax Hi -- On Sun, 7 Sep 2008, Patrick Li wrote: > Hi David, > Mmm, I'm really not sure how it can be accomplished. I agree, yielding > an object to a block is a rock solid approach. It's a technique that I > love, and use everywhere. Which is actually, what led me to think about > this: > > Everywhere in my code is stuff like this: > > # from my event listening system... > listen do |listener| > listener.listenTo(:playerKilledEvent) do > ... > end > end > > # from my drawing system... > engine.drawFrame do |drawer| > drawer.drawRect(...) > drawer.drawCircle(...) > end > > # from my collision system... > engine.detectCollision do |collider| > @collided = collider.checkCollision(@myRect, @myCircle) > end > > Which begs the question: Is there a better way? Personally I do not at all rule out this in cases like those: drawer = engine.draw_frame drawer.draw_rect(...) drawer.draw_circle(...) etc. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!