rubex

https://github.com/sciruby/rubex

Ruby

rubex - A Ruby-like language for writing Ruby C extensions.

Rubex::SymbolTable::Scope::BeginBlock#method_missing

IMPORTANT NOTE TO PROGRAMMER:

A problem with the BeginBlock is that in the Ruby world, it must share
scope with the method above and below it. However, when translating to
C, the begin block must be put inside its own C function, which is then
sent as a callback to rb_protect().

As a result, it is necesary to 'upgrade' the local variables present
inside the begin block to C global variables so that they can be shared
between the callback C function encapsulating the begin block and the 
ruby method that has a begin block defined inside it.

Now, since variables must be shared, it is also necessary to share the
scopes between these functions. Therefore, the BeginBlock scope uses
method_missing to capture whatever methods calls it has received and 
redirect those to @outer_scope, which is the scope of the method that
contains the begin block. Whenever a method call to @outer_scope returns
a SymbolTable::Entry object, that object is read to check if it is a
variable. If yes, it is added into the @block_entries Array which
stores the entries that need to be upgraded to C global variables.

Now as a side effect of this behaviour, the various *_entries Arrays
of @outer_scope get carried forward into this begin block callback.
Therefore these variables get declared inside the begin block callback
as well. So whenever one of these Arrays is called for this particular
scope, we return an empty array so that nothing gets declared.

Source | Google | Stack overflow

Edit

git clone [email protected]:sciruby/rubex.git

cd rubex

open lib/rubex/symbol_table/scope.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Rubex--SymbolTable--Scope--BeginBlock-method_missing-for-pr


# Commit to git

git add lib/rubex/symbol_table/scope.rbgit commit -m "better docs for Rubex::SymbolTable::Scope::BeginBlock#method_missing"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Rubex--SymbolTable--Scope--BeginBlock-method_missing-for-pr

hub pull-request


# Celebrate!