Instance methods are not usable inside grammars#32
Instance methods are not usable inside grammars#32wdrexler wants to merge 1 commit intoadhearsion:developfrom
Conversation
|
So current theory is that while this fails... RubySpeech::GRXML.draw root: 'root', tag_format: 'semantics/1.0' do
rule id: 'root', scope: 'public' do
item { my_method }
end
end...this would work... RubySpeech::GRXML.draw root: 'root', tag_format: 'semantics/1.0' do
item { my_method }
endThe existing test for this needs to be extended to cover invocation in a nested block. |
|
So I've written a new test that covers invocation in a nested block. It fails, as expected. How would we fix this, @benlangfeld? |
|
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? |
spec/ruby_speech/grxml_spec.rb
Outdated
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.
|
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. |
|
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.