Skip to content

Commit b3a2eba

Browse files
authored
Merge pull request #2 from ruby/module_private_completion
Fix private method completion inside module
2 parents 2da03f8 + ec44527 commit b3a2eba

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/repl_type_completor/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def initialize(module_or_class)
162162
end
163163
def transform() = yield(self)
164164
def methods() = @module_or_class.methods
165-
def all_methods() = methods | Kernel.methods
165+
def all_methods() = methods | @module_or_class.private_methods
166166
def constants() = @module_or_class.constants
167167
def types() = [self]
168168
def nillable?() = false

test/repl_type_completor/test_types.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,30 @@ def foobar; end
6666
private def foobaz; end
6767
end
6868
String.define_method(:foobarbaz) {}
69-
targets = [:foobar, :foobaz, :foobarbaz]
69+
targets = [:foobar, :foobaz, :foobarbaz, :rand]
7070
type = ReplTypeCompletor::Types.type_from_object s
7171
assert_equal [:foobar, :foobarbaz], targets & type.methods
72-
assert_equal [:foobar, :foobaz, :foobarbaz], targets & type.all_methods
72+
assert_equal [:foobar, :foobaz, :foobarbaz, :rand], targets & type.all_methods
7373
assert_equal [:foobarbaz], targets & ReplTypeCompletor::Types::STRING.methods
74-
assert_equal [:foobarbaz], targets & ReplTypeCompletor::Types::STRING.all_methods
74+
assert_equal [:foobarbaz, :rand], targets & ReplTypeCompletor::Types::STRING.all_methods
7575
ensure
7676
String.remove_method :foobarbaz
7777
end
7878

79+
def test_singleton_type_methods
80+
m = Module.new do
81+
class << self
82+
def foobar; end
83+
private def foobaz; end
84+
end
85+
end
86+
type = ReplTypeCompletor::Types::SingletonType.new(m)
87+
assert_include type.methods, :foobar
88+
assert_not_include type.methods, :foobaz
89+
assert_include type.all_methods, :foobaz
90+
assert_include type.all_methods, :rand
91+
end
92+
7993
def test_basic_object_methods
8094
bo = BasicObject.new
8195
def bo.foobar; end

0 commit comments

Comments
 (0)