benlangfeld/ruby_speech — pull request #32 by wdrexler (2014-06-20 18:46:09+00:00)
Title: Instance methods are not usable inside grammars

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:
```
/Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:277:in `method_missing': undefined local variable or method `my_method' for
:RubySpeech::GRXML::Item (NameError)
from ./rs_test.rb:14:in `block (3 levels) in grammar'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `instance_eval'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `eval_dsl_block'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:78:in `build'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:57:in `initialize'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:273:in `new'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:273:in `method_missing'
from ./rs_test.rb:14:in `block (2 levels) in grammar'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `instance_eval'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `eval_dsl_block'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:78:in `build'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:57:in `initialize'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:273:in `new'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:273:in `method_missing'
from ./rs_test.rb:13:in `block in grammar'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `instance_eval'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/generic_element.rb:126:in `eval_dsl_block'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/grxml.rb:25:in `block in draw'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/grxml.rb:23:in `tap'
from /Users/wdrexler/.rvm/gems/ruby-2.1.2/bundler/gems/ruby_speech-a3a837c0106f/lib/ruby_speech/grxml.rb:23:in `draw'
from ./rs_test.rb:12:in `grammar'
from ./rs_test.rb:4:in `run'
from ./rs_test.rb:20:in `

'
```

This error does not occur when either:
1. The methods are declared at the top level (i.e. outside of a class) or
2. If a local variable is assigned to the return value of the method before the `RubySpeech::GRXML.draw` block starts

This was tested against latest develop.