mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] do not escape a predicate method for doc namespace
* Fixes #88
d431a30af4
This commit is contained in:
parent
4bb683a570
commit
f594775230
2 changed files with 19 additions and 11 deletions
|
@ -47,7 +47,7 @@ module IRB
|
||||||
when /^((["'`]).*\2)\.([^.]*)$/
|
when /^((["'`]).*\2)\.([^.]*)$/
|
||||||
# String
|
# String
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($3)
|
message = $3
|
||||||
|
|
||||||
candidates = String.instance_methods.collect{|m| m.to_s}
|
candidates = String.instance_methods.collect{|m| m.to_s}
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
|
@ -59,7 +59,7 @@ module IRB
|
||||||
when /^(\/[^\/]*\/)\.([^.]*)$/
|
when /^(\/[^\/]*\/)\.([^.]*)$/
|
||||||
# Regexp
|
# Regexp
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = $2
|
||||||
|
|
||||||
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
|
@ -71,7 +71,7 @@ module IRB
|
||||||
when /^([^\]]*\])\.([^.]*)$/
|
when /^([^\]]*\])\.([^.]*)$/
|
||||||
# Array
|
# Array
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = $2
|
||||||
|
|
||||||
candidates = Array.instance_methods.collect{|m| m.to_s}
|
candidates = Array.instance_methods.collect{|m| m.to_s}
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
|
@ -83,7 +83,7 @@ module IRB
|
||||||
when /^([^\}]*\})\.([^.]*)$/
|
when /^([^\}]*\})\.([^.]*)$/
|
||||||
# Proc or Hash
|
# Proc or Hash
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = $2
|
||||||
|
|
||||||
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
|
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
|
||||||
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
|
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
|
||||||
|
@ -117,7 +117,7 @@ module IRB
|
||||||
when /^([A-Z].*)::([^:.]*)$/
|
when /^([A-Z].*)::([^:.]*)$/
|
||||||
# Constant or class methods
|
# Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
message = Regexp.quote($2)
|
message = $2
|
||||||
begin
|
begin
|
||||||
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
||||||
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
||||||
|
@ -134,7 +134,7 @@ module IRB
|
||||||
# Symbol
|
# Symbol
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = $3
|
||||||
|
|
||||||
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
candidates = Symbol.instance_methods.collect{|m| m.to_s}
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
|
@ -147,7 +147,7 @@ module IRB
|
||||||
# Numeric
|
# Numeric
|
||||||
receiver = $~[:num]
|
receiver = $~[:num]
|
||||||
sep = $~[:sep]
|
sep = $~[:sep]
|
||||||
message = Regexp.quote($~[:mes])
|
message = $~[:mes]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
instance = eval(receiver, bind)
|
instance = eval(receiver, bind)
|
||||||
|
@ -169,7 +169,7 @@ module IRB
|
||||||
# Numeric(0xFFFF)
|
# Numeric(0xFFFF)
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = $3
|
||||||
|
|
||||||
begin
|
begin
|
||||||
instance = eval(receiver, bind)
|
instance = eval(receiver, bind)
|
||||||
|
@ -201,7 +201,7 @@ module IRB
|
||||||
# variable.func or func.func
|
# variable.func or func.func
|
||||||
receiver = $1
|
receiver = $1
|
||||||
sep = $2
|
sep = $2
|
||||||
message = Regexp.quote($3)
|
message = $3
|
||||||
|
|
||||||
gv = eval("global_variables", bind).collect{|m| m.to_s}.push("true", "false", "nil")
|
gv = eval("global_variables", bind).collect{|m| m.to_s}.push("true", "false", "nil")
|
||||||
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
||||||
|
@ -244,7 +244,7 @@ module IRB
|
||||||
# unknown(maybe String)
|
# unknown(maybe String)
|
||||||
|
|
||||||
receiver = ""
|
receiver = ""
|
||||||
message = Regexp.quote($1)
|
message = $1
|
||||||
|
|
||||||
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
||||||
if doc_namespace
|
if doc_namespace
|
||||||
|
@ -294,7 +294,7 @@ module IRB
|
||||||
Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
|
Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
|
||||||
|
|
||||||
def self.select_message(receiver, message, candidates, sep = ".")
|
def self.select_message(receiver, message, candidates, sep = ".")
|
||||||
candidates.grep(/^#{message}/).collect do |e|
|
candidates.grep(/^#{Regexp.quote(message)}/).collect do |e|
|
||||||
case e
|
case e
|
||||||
when /^[a-zA-Z_]/
|
when /^[a-zA-Z_]/
|
||||||
receiver + sep + e
|
receiver + sep + e
|
||||||
|
|
|
@ -47,5 +47,13 @@ module TestIRB
|
||||||
assert_include candidates, word
|
assert_include candidates, word
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_complete_predicate?
|
||||||
|
candidates = IRB::InputCompletor.retrieve_completion_data("1.posi", bind: binding)
|
||||||
|
assert_equal %w[1.positive?], candidates
|
||||||
|
|
||||||
|
namespace = IRB::InputCompletor.retrieve_completion_data("1.positive?", bind: binding, doc_namespace: true)
|
||||||
|
assert_equal "Integer.positive?", namespace
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue