Permalink
Browse files

Rescue NameError when retrieving instance methods of a class.

  • Loading branch information...
alloy committed Mar 30, 2011
1 parent 46850c3 commit f8d2c8593825f98c6aa8c62d439cb1e940e91286
Showing with 12 additions and 1 deletion.
  1. +6 −1 lib/irb/ext/completion.rb
  2. +6 −0 spec/ext/completion_spec.rb
@@ -76,6 +76,8 @@ def instance_methods
def instance_methods_of(klass_name)
klass = evaluate(klass_name)
INCLUDE_MACRUBY_HELPERS ? klass.instance_methods(true, true) : klass.instance_methods(true)
+ rescue NameError
+ nil
end
# TODO: test and or fix the fact that we need to get constants from the
@@ -109,11 +111,14 @@ def results
filter = stack[2][VALUE] if stack[2]
receiver = "#{klass}.new"
methods = instance_methods_of(klass)
+ return if methods.nil?
elsif stack[1][VALUE] == 'alloc' && INCLUDE_MACRUBY_HELPERS
klass = stack[0][VALUE][VALUE]
filter = stack[2][VALUE] if stack[2]
receiver = "#{klass}.alloc"
- methods = instance_methods_of(klass).grep(/^init[A-Z]?/)
+ methods = instance_methods_of(klass)
+ return if methods.nil?
+ methods = methods.grep(/^init[A-Z]?/)
else
filter = root[CALLEE][VALUE]
filter = stack[1][VALUE]
@@ -221,6 +221,9 @@ def initWithNothing; end
@context.__evaluate__("klass = Playground")
complete("klass.new.").should == wrap_array(imethods, 'klass.new')
complete("klass.new.a_local_m").should == %w{ klass.new.a_local_method }
+
+ complete("DoesNotExist.new").should == nil
+ complete("DoesNotExist.new.a_local_m").should == nil
end
if IRB::Completion::INCLUDE_MACRUBY_HELPERS
@@ -230,6 +233,9 @@ def initWithNothing; end
complete("NSSpeechSynthesizer.alloc.initWithVo").should == %w{ NSSpeechSynthesizer.alloc.initWithVoice }
@context.__evaluate__("klass = NSSpeechSynthesizer")
complete("klass.alloc.ini").should == %w{ klass.alloc.init klass.alloc.initWithVoice }
+
+ complete("DoesNotExist.alloc").should == nil
+ complete("DoesNotExist.alloc.initWithVo").should == nil
end
end
end

0 comments on commit f8d2c85

Please sign in to comment.