mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
local-variables command. :neckbeard:
This commit is contained in:
parent
322313edb7
commit
38598429fb
2 changed files with 31 additions and 0 deletions
21
lib/pry/commands/local_variables.rb
Normal file
21
lib/pry/commands/local_variables.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Pry
|
||||
Pry::Commands.create_command 'local-variables' do
|
||||
group 'Context'
|
||||
description 'Show hash of local vars, sorted by descending size'
|
||||
|
||||
def process
|
||||
pry_vars = [
|
||||
:____, :___, :__, :_, :_dir_, :_file_, :_ex_, :_pry_, :_out_, :_in_ ]
|
||||
loc_names = target.eval('local_variables').reject do |e|
|
||||
pry_vars.include? e
|
||||
end
|
||||
name_value_pairs = loc_names.map do |name|
|
||||
[name, (target.eval name.to_s)]
|
||||
end
|
||||
name_value_pairs.sort! do |(a,av), (b,bv)|
|
||||
bv.to_s.size <=> av.to_s.size
|
||||
end
|
||||
Pry.print.call _pry_.output, Hash[name_value_pairs]
|
||||
end
|
||||
end
|
||||
end
|
10
test/test_commands/test_local_variables.rb
Normal file
10
test/test_commands/test_local_variables.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'helper'
|
||||
|
||||
describe 'local-variables' do
|
||||
it 'should find locals and sort by descending size' do
|
||||
mock_pry("a = 'asdf'; b = 'x'\nlocal-variables").should =~ /'asdf'.*'x'/
|
||||
end
|
||||
it 'should not list pry noise' do
|
||||
mock_pry('local-variables').should.not =~ /_(?:dir|file|ex|pry|out|in)_/
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue