(#21508) Make local variables available to templates as instance vars

The problem was that templates reference scope variables using
instance variables e.g. @myvar, these were configured from the
hash returned by Scope#to_hash. That method did not consider
ephemeral scopes.

The solution was to add collection of the emphmeral scopes' (that
represent local scopes) variables and include them in the hash.

As before, the match scopes (i.e. for $0 - $n) are not included in
the result.