Skip to content

Commit

Permalink
[ruby/reline] Change Reline.add_dialog_proc(name, nil) to properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored and matzbot committed Apr 15, 2023
1 parent 34f484d commit 19aa30d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/reline.rb
Expand Up @@ -166,9 +166,13 @@ def dig_perfect_match_proc=(p)

DialogProc = Struct.new(:dialog_proc, :context)
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)
@dialog_proc_list[name_sym] = DialogProc.new(p, context)
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)
end
end

def dialog_proc(name_sym)
Expand Down
3 changes: 3 additions & 0 deletions test/reline/test_reline.rb
Expand Up @@ -321,6 +321,9 @@ def test_add_dialog_proc
d = Reline.dialog_proc(:test_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 {}
Reline.add_dialog_proc(:test_lambda, l)
d = Reline.dialog_proc(:test_lambda)
Expand Down

0 comments on commit 19aa30d

Please sign in to comment.