Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reline.add_dialog_proc should not accept nil as proc #532

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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