Skip to content

Commit

Permalink
Change Reline.add_dialog_proc(name, nil) to properly remove dialog_pr…
Browse files Browse the repository at this point in the history
…oc (ruby#532)
  • Loading branch information
tompng authored Apr 15, 2023
1 parent c6bc257 commit 43283b2
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 43283b2

Please sign in to comment.