зеркало из https://github.com/github/ruby.git
[ruby/reline] Change Reline.add_dialog_proc(name, nil) to properly
remove dialog_proc (https://github.com/ruby/reline/pull/532) https://github.com/ruby/reline/commit/43283b2f37
This commit is contained in:
Родитель
34f484d233
Коммит
19aa30d5d5
|
@ -166,10 +166,14 @@ module Reline
|
||||||
|
|
||||||
DialogProc = Struct.new(:dialog_proc, :context)
|
DialogProc = Struct.new(:dialog_proc, :context)
|
||||||
def add_dialog_proc(name_sym, p, context = nil)
|
def add_dialog_proc(name_sym, p, context = nil)
|
||||||
raise ArgumentError unless p.respond_to?(:call) or p.nil?
|
|
||||||
raise ArgumentError unless name_sym.instance_of?(Symbol)
|
raise ArgumentError unless name_sym.instance_of?(Symbol)
|
||||||
|
if p.nil?
|
||||||
|
@dialog_proc_list.delete(name_sym)
|
||||||
|
else
|
||||||
|
raise ArgumentError unless p.respond_to?(:call)
|
||||||
@dialog_proc_list[name_sym] = DialogProc.new(p, context)
|
@dialog_proc_list[name_sym] = DialogProc.new(p, context)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def dialog_proc(name_sym)
|
def dialog_proc(name_sym)
|
||||||
@dialog_proc_list[name_sym]
|
@dialog_proc_list[name_sym]
|
||||||
|
|
|
@ -321,6 +321,9 @@ class Reline::Test < Reline::TestCase
|
||||||
d = Reline.dialog_proc(:test_proc)
|
d = Reline.dialog_proc(:test_proc)
|
||||||
assert_equal(dummy_proc_2, d.dialog_proc)
|
assert_equal(dummy_proc_2, d.dialog_proc)
|
||||||
|
|
||||||
|
Reline.add_dialog_proc(:test_proc, nil)
|
||||||
|
assert_nil(Reline.dialog_proc(:test_proc))
|
||||||
|
|
||||||
l = lambda {}
|
l = lambda {}
|
||||||
Reline.add_dialog_proc(:test_lambda, l)
|
Reline.add_dialog_proc(:test_lambda, l)
|
||||||
d = Reline.dialog_proc(:test_lambda)
|
d = Reline.dialog_proc(:test_lambda)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче