Skip to content

Instantly share code, notes, and snippets.

@Who828
Created January 27, 2015 18:46
Show Gist options
  • Save Who828/397585db748e6a998e14 to your computer and use it in GitHub Desktop.
Save Who828/397585db748e6a998e14 to your computer and use it in GitHub Desktop.
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