Created
January 27, 2015 18:46
-
-
Save Who828/397585db748e6a998e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static RubyArray local_variables19(ThreadContext context, IRubyObject recv) { | |
final Ruby runtime = context.runtime; | |
HashSet<String> encounteredLocalVariables = new HashSet<String>(); | |
RubyArray allLocalVariables = runtime.newArray(); | |
DynamicScope currentScope = context.getCurrentScope(); | |
while (currentScope != null) { | |
RubyArray localVariables = runtime.newArray(); | |
for (String name : currentScope.getAllNamesInScope()) { | |
if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) { | |
localVariables.push(runtime.newSymbol(name)); | |
encounteredLocalVariables.add(name); | |
} | |
} | |
allLocalVariables.push(localVariables); | |
currentScope = currentScope.getParentScope(); | |
} | |
allLocalVariables.reverse_bang(); | |
allLocalVariables.flatten_bang(context); | |
return allLocalVariables; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment