Skip to content

Commit

Permalink
Merge pull request #867 from p8/refactor/remove-string-encode-conditi…
Browse files Browse the repository at this point in the history
…onal

Remove String#encode conditional required by Ruby < 2.6
  • Loading branch information
rafaelfranca committed Feb 26, 2024
2 parents 8d6edeb + dff675a commit 3984381
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions lib/thor/shell/table_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3984381

Please sign in to comment.