shoes/shoes4 — pull request #503 by wasnotrice (2013-12-17 06:28:13+00:00)
Title: Another approach to a clean execution context (proof of concept)

I showed one way to clean up our block execution context in #501, by evaling blocks in a `Shoes::Context` object, which isolated evaled code from the state of the `Shoes::App` object. As @PragTob [pointed out](https://github.com/shoes/shoes4/pull/501#issuecomment-30605034), this had the disadvantage that, in a user's app, `self` would refer not to the `Shoes::App` object, but instead to the `Shoes::Context` object.

Here's another, backwards, approach. Here, all of the `Shoes::App`'s state gets pulled into a `Shoes::AppProxy` object. This proxy object is used in place of the app internally (it *is* the app instance as far as the other DSL classes are concerned), but user code gets evaled in the context of the `Shoes::App` object. The `Shoes::App` object only has one instance variable, the cleverly-named and very low-lying `@__private_proxy__`. Tomatoes, tomatoes.

For reference, here (again) is the test app from #501 (which is itself from #492):

```ruby
def width
"EXTRA WIDE"
end

def breadth
"EXTRA BROAD"
end

Shoes.app do
button "breadth" do
title "Breadth: #{breadth}" # Breadth: EXTRA BROAD
end

button "width" do
title "Width: #{width}" # Width: EXTRA WIDE
end

button "gui" do
@gui = "EXTRA GUI"
title "Gui: #{@gui}" # EXTRA GUI
end
end
```

and here's that app executed with changes in this pull request:

![screen shot 2013-12-17 at 12 20 48 am](https://f.cloud.github.com/assets/908/1761943/7efd6936-66e3-11e3-8867-3c269fbcad38.png)

As in #501, this is not a fully-baked solution. It runs this test app, as well as `samples/sample1.rb` and `samples/sample2.rb`. It probably won't run everything though. It's just a flavor of what could be.

What say you?