Uh oh!
There was an error while loading. Please reload this page.
Instance methods are not usable inside grammars - #32
Conversation
benlangfeld
commented
Jun 20, 2014
So current theory is that while this fails... RubySpeech::GRXML.drawroot: 'root',tag_format: 'semantics/1.0'doruleid: 'root',scope: 'public'doitem{my_method}endend...this would work... RubySpeech::GRXML.drawroot: 'root',tag_format: 'semantics/1.0'doitem{my_method}endThe existing test for this needs to be extended to cover invocation in a nested block. |
wdrexler
commented
Jun 20, 2014
So I've written a new test that covers invocation in a nested block. It fails, as expected. How would we fix this, @benlangfeld? |
benlangfeld
commented
Jun 20, 2014
First off, submit the spec as a pull request to replace this issue (or convert this one). As for a fix, either recursively walk up the tree in method_missing or directly grab the block context from the root of the tree. The latter is more efficient but the former more closely respects normal closure binding semantics. Thoughts? |
There was a problem hiding this comment.
Should I go ahead and use 1.9 syntax? The only reason I didn't in the first place was that the existing specs used 1.8 syntax.
There was a problem hiding this comment.
In all touched lines here, yeah. We should migrate piece by piece.
wdrexler
commented
Jun 20, 2014
So I'm leaning towards walking up the tree instead of just grabbing the root element. Without knowing the actual performance impact of grabbing the block context of the root element (in, say, an Adhearsion app, is walking up the tree really going to be a bottleneck?), I'd say that we're better off going with the more semantically valid approach. |
benlangfeld
commented
Jun 20, 2014
Go for it :) |
It seems that when there is a method inside a class that returns a grammar, and that grammar uses the return values of other methods inside the class, RubySpeech throws an error.
Code looks like this: https://gist.github.com/wdrexler/f0b229d7dfb7a9629dbe
The error returned is:
This error does not occur when either:
RubySpeech::GRXML.drawblock startsThis was tested against latest develop.