Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only use the extra argument to Module#instance_methods to include obj…

…c methods on MacRuby.
  • Loading branch information...
commit 46850c375604c25d8c40110986ff2418baf65f6c 1 parent 7969bd4
@alloy alloy authored
Showing with 15 additions and 6 deletions.
  1. +6 −3 lib/irb/ext/completion.rb
  2. +9 −3 spec/ext/completion_spec.rb
View
9 lib/irb/ext/completion.rb
@@ -8,6 +8,8 @@
module IRB
class Completion
+ INCLUDE_MACRUBY_HELPERS = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
+
# Convenience constants for sexp access of Ripper::SexpBuilder.
TYPE = 0
VALUE = 1
@@ -71,8 +73,9 @@ def instance_methods
context.object.methods.map(&:to_s)
end
- def instance_methods_of(klass)
- evaluate(klass).instance_methods(true, true)
+ def instance_methods_of(klass_name)
+ klass = evaluate(klass_name)
+ INCLUDE_MACRUBY_HELPERS ? klass.instance_methods(true, true) : klass.instance_methods(true)
end
# TODO: test and or fix the fact that we need to get constants from the
@@ -106,7 +109,7 @@ def results
filter = stack[2][VALUE] if stack[2]
receiver = "#{klass}.new"
methods = instance_methods_of(klass)
- elsif stack[1][VALUE] == 'alloc' && defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
+ elsif stack[1][VALUE] == 'alloc' && INCLUDE_MACRUBY_HELPERS
klass = stack[0][VALUE][VALUE]
filter = stack[2][VALUE] if stack[2]
receiver = "#{klass}.alloc"
View
12 spec/ext/completion_spec.rb
@@ -209,15 +209,21 @@ def initWithNothing; end
end
it "returns *all* public instance methods of the class (the receiver) that ::new is called on" do
- complete("Playground.new.").should == wrap_array(Playground.instance_methods(true, true), 'Playground.new')
+ if IRB::Completion::INCLUDE_MACRUBY_HELPERS
+ imethods = Playground.instance_methods(true, true)
+ else
+ imethods = Playground.instance_methods(true)
+ end
+
+ complete("Playground.new.").should == wrap_array(imethods, 'Playground.new')
complete("Playground.new.a_local_m").should == %w{ Playground.new.a_local_method }
@context.__evaluate__("klass = Playground")
- complete("klass.new.").should == wrap_array(Playground.instance_methods(true, true), 'klass.new')
+ complete("klass.new.").should == wrap_array(imethods, 'klass.new')
complete("klass.new.a_local_m").should == %w{ klass.new.a_local_method }
end
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
+ if IRB::Completion::INCLUDE_MACRUBY_HELPERS
it "returns *all* instance methods that are prefixed with `init' of the class (the receiver) that ::alloc is called on" do
framework 'AppKit'
complete("NSSpeechSynthesizer.alloc.ini").should == %w{ NSSpeechSynthesizer.alloc.init NSSpeechSynthesizer.alloc.initWithVoice }
Please sign in to comment.
Something went wrong with that request. Please try again.