From dff675a34b9242520437f2d138c6b6670e829658 Mon Sep 17 00:00:00 2001 From: Petrik Date: Fri, 5 Jan 2024 21:55:31 +0100 Subject: [PATCH] Remove String#encode conditional required by Ruby < 2.6 As Thor requires Ruby >= 2.6 we don't need to check if String responds to `#encode` as this is supported since Ruby 1.9.2 at least: https://www.rubydoc.info/stdlib/core/1.9.2/String:encode --- lib/thor/shell/table_printer.rb | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/thor/shell/table_printer.rb b/lib/thor/shell/table_printer.rb index 88828954..6ca57b2b 100644 --- a/lib/thor/shell/table_printer.rb +++ b/lib/thor/shell/table_printer.rb @@ -102,33 +102,17 @@ def print_border_separator def truncate(string) return string unless @truncate - as_unicode do - chars = string.chars.to_a - if chars.length <= @truncate - chars.join - else - chars[0, @truncate - 3 - @indent].join + "..." - end + chars = string.chars.to_a + if chars.length <= @truncate + chars.join + else + chars[0, @truncate - 3 - @indent].join + "..." end end def indentation " " * @indent end - - if "".respond_to?(:encode) - def as_unicode - yield - end - else - def as_unicode - old = $KCODE # rubocop:disable Style/GlobalVars - $KCODE = "U" # rubocop:disable Style/GlobalVars - yield - ensure - $KCODE = old # rubocop:disable Style/GlobalVars - end - end end end end