From fc0289b42bff999ab1522936ebc07197db731395 Mon Sep 17 00:00:00 2001 From: Mari Imaizumi Date: Wed, 15 Jan 2025 23:09:16 +0900 Subject: [PATCH] Set default value for Reline.input, Reline.output and Reline.special_prefixes --- lib/reline.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 5d1fcbf8e8..473a2686ff 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -114,7 +114,11 @@ def filename_quote_characters=(v) end def special_prefixes=(v) - @special_prefixes = v.encode(encoding) + if v.nil? + @special_prefixes = '' + else + @special_prefixes = v.encode(encoding) + end end def completion_case_fold=(v) @@ -174,14 +178,25 @@ def dialog_proc(name_sym) end def input=(val) - raise TypeError unless val.respond_to?(:getc) or val.nil? - if val.respond_to?(:getc) && io_gate.respond_to?(:input=) - io_gate.input = val + if val.nil? + io_gate.input = STDIN + return + elsif !val.respond_to?(:getc) + raise TypeError end + + io_gate.input = val end def output=(val) - raise TypeError unless val.respond_to?(:write) or val.nil? + if val.nil? + @output = STDOUT + io_gate.output = STDOUT + return + elsif !val.respond_to?(:write) + raise TypeError + end + @output = val io_gate.output = val end