[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Request for Block local methods, and Proc syntax

Yukihiro Matsumoto

9/6/2008 4:23:00 PM

Hi,

In message "Re: Request for Block local methods, and Proc syntax"
on Sun, 7 Sep 2008 01:08:01 +0900, Patrick Li <patrickli_2001@hotmail.com> writes:

|But I still think it's worth thinking about. In my opinion, DSL's is
|Ruby's greatest strength. It's the one feature where Ruby is light years
|ahead of other languages. And context-sensitive methods are vital to
|DSL's. I think putting in some thought towards this direction could
|really make Ruby stand out.

You can switch the context (the receiver) using instance_eval. Do we
need more?

matz.

4 Answers

Patrick Li

9/6/2008 5:17:00 PM

0

I think we need a way to preserve the scope elegantly, so that methods
and instance variables can still be accessed.

The solutions posted so far are all pretty fragile still.
--
Posted via http://www.ruby-....

David A. Black

9/6/2008 5:23:00 PM

0

Hi --

On Sun, 7 Sep 2008, Patrick Li wrote:

> I think we need a way to preserve the scope elegantly, so that methods
> and instance variables can still be accessed.
>
> The solutions posted so far are all pretty fragile still.

It sounds like you want some kind of bifurcation of self, so that
instance variables are resolved against one object and method calls
against another. I'm not sure how that would work, even theoretically,
and it sounds like it would be more fragile than just yielding an
object to a block.


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.r... for details and updates!

Patrick Li

9/6/2008 5:50:00 PM

0

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?
-Patrick
--
Posted via http://www.ruby-....

David A. Black

9/6/2008 7:47:00 PM

0

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.r... for details and updates!