[ruby/irb] Detect the variable class to show doc

https://github.com/ruby/irb/commit/33b9bec954
This commit is contained in:
aycabta 2021-09-02 21:34:53 +09:00 коммит произвёл git
Родитель f734590f8e
Коммит 4e40b7ddb0
2 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -315,12 +315,19 @@ module IRB
end
else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords
if doc_namespace
candidates.find{ |i| i == input }
vars = eval("local_variables | instance_variables", bind).collect{|m| m.to_s}
perfect_match_var = vars.find{|m| m.to_s == input}
if perfect_match_var
eval("#{perfect_match_var}.class.name", bind)
else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords
candidates.find{ |i| i == input }
end
else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
candidates |= ReservedWords
candidates.grep(/^#{Regexp.quote(input)}/)
end
end

Просмотреть файл

@ -83,5 +83,11 @@ module TestIRB
assert_include candidates, word
end
end
def test_complete_variable
str_example = ''
assert_include(IRB::InputCompletor.retrieve_completion_data("str_examp", bind: binding), "str_example")
assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example", bind: binding, doc_namespace: true), "String")
end
end
end