Skip to content

Commit

Permalink
Fix private method completion inside module
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Dec 1, 2023
1 parent 6d0a9d1 commit 1dddd8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/repl_type_completor/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def initialize(module_or_class)
end
def transform() = yield(self)
def methods() = @module_or_class.methods
def all_methods() = methods | Kernel.methods
def all_methods() = methods | @module_or_class.private_methods
def constants() = @module_or_class.constants
def types() = [self]
def nillable?() = false
Expand Down
20 changes: 17 additions & 3 deletions test/repl_type_completor/test_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,30 @@ def foobar; end
private def foobaz; end
end
String.define_method(:foobarbaz) {}
targets = [:foobar, :foobaz, :foobarbaz]
targets = [:foobar, :foobaz, :foobarbaz, :rand]
type = ReplTypeCompletor::Types.type_from_object s
assert_equal [:foobar, :foobarbaz], targets & type.methods
assert_equal [:foobar, :foobaz, :foobarbaz], targets & type.all_methods
assert_equal [:foobar, :foobaz, :foobarbaz, :rand], targets & type.all_methods
assert_equal [:foobarbaz], targets & ReplTypeCompletor::Types::STRING.methods
assert_equal [:foobarbaz], targets & ReplTypeCompletor::Types::STRING.all_methods
assert_equal [:foobarbaz, :rand], targets & ReplTypeCompletor::Types::STRING.all_methods
ensure
String.remove_method :foobarbaz
end

def test_singleton_type_methods
m = Module.new do
class << self
def foobar; end
private def foobaz; end
end
end
type = ReplTypeCompletor::Types::SingletonType.new(m)
assert_include type.methods, :foobar
assert_not_include type.methods, :foobaz
assert_include type.all_methods, :foobaz
assert_include type.all_methods, :rand
end

def test_basic_object_methods
bo = BasicObject.new
def bo.foobar; end
Expand Down

0 comments on commit 1dddd8c

Please sign in to comment.