-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instance methods are not usable inside grammars #32
base: develop
Are you sure you want to change the base?
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 }
end The 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? |
'bar' | ||
end | ||
drawn_doc = GRXML.draw do | ||
rule :id => foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.draw
block startsThis was tested against latest develop.