Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created March 27, 2014 11:58
Show Gist options
  • Save stevenbristol/9806016 to your computer and use it in GitHub Desktop.
Save stevenbristol/9806016 to your computer and use it in GitHub Desktop.
# called in main
pry(main)> local_variables
=> [:__, :_, :_dir_, :_file_, :_ex_, :_pry_, :_out_, :_in_, :_erbout]
# called in method with no local vars
pry(main)> def a; local_variables; end
=> nil
pry(main)> a
=> []
#called in method with 1 local var
pry(main)> def a; b = 1; local_variables; end
=> nil
pry(main)> a
=> [:b]
# getting the values and the names (which i what is really needed)
pry(main)> def a; b = 1; local_variables.each {|name| p "#{name}: #{eval name.to_s}"}; end
=> nil
pry(main)> a
"b: 1"
=> [:b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment