mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
lib/pry/commands/ls.rb: fix ls -c
on top-level
This is rather an odd bug introduced by this commit: "Add support for
BasicObjects to `ls`"[1]. `ls -c` works, if you install it as a gem, but
it refuses to display anything, if you run it via `rake pry`. Moreover,
I've tried to write a failing test without changing the implementation,
but the test suite couldn't fail. Let's fix this issue, because it can
save us a lot of time, avoiding the situation when one stumble upon this
oddity once again.
[1]: ac683892d1
This commit is contained in:
parent
32b7290c75
commit
6721f0ccd6
2 changed files with 21 additions and 1 deletions
|
@ -185,7 +185,20 @@ class Pry
|
|||
end
|
||||
|
||||
def module_to_interrogate
|
||||
interrogating_a_module? ? object_to_interrogate : (class << object_to_interrogate; self.ancestors.first; end)
|
||||
if interrogating_a_module?
|
||||
object_to_interrogate
|
||||
elsif instance_of_object?
|
||||
object_to_interrogate.class
|
||||
else
|
||||
class << object_to_interrogate; self.ancestors.first; end
|
||||
end
|
||||
end
|
||||
|
||||
def instance_of_object?
|
||||
superclass = object_to_interrogate.instance_eval do
|
||||
(class << self; self; end).superclass
|
||||
end
|
||||
superclass == Object
|
||||
end
|
||||
|
||||
def write_out_globals
|
||||
|
|
|
@ -141,6 +141,13 @@ describe "ls" do
|
|||
end
|
||||
|
||||
describe "constants" do
|
||||
it "works on top-level" do
|
||||
toplevel_consts = pry_eval('ls -c')
|
||||
[/RUBY_PLATFORM/, /ARGF/, /STDOUT/].each do |const|
|
||||
toplevel_consts.should =~ const
|
||||
end
|
||||
end
|
||||
|
||||
it "should show constants defined on the current module" do
|
||||
pry_eval("class TempFoo1; BARGHL = 1; end", "ls TempFoo1").should =~ /BARGHL/
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue