From 9bd2b66fe3f0eb8ecc5bc867a7ba866725cc6c2d Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 22 Dec 2023 19:40:25 +1300 Subject: [PATCH] Remove unused String.shorten extension (#204) It's only used in one view, and that view is unused and broken. And anyway, Rails 3 has a built-in truncate method that we can use instead (it's slightly different in how it interprets the length). Suggested-by: Ben Anderson --- app/views/test_cases/index.html.erb | 4 ++-- config/environment.rb | 4 ---- lib/ext/string.rb | 9 --------- 3 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 lib/ext/string.rb diff --git a/app/views/test_cases/index.html.erb b/app/views/test_cases/index.html.erb index 203af89f..39b1c61f 100644 --- a/app/views/test_cases/index.html.erb +++ b/app/views/test_cases/index.html.erb @@ -18,8 +18,8 @@ <% @test_cases.each do |test_case| %> - <%= simple_format(test_case.input.shorten) %> - <%= simple_format(test_case.output.shorten) %> + <%= simple_format(test_case.input.truncate(100)) %> + <%= simple_format(test_case.output.truncate(100)) %> <%= test_case.test_set_ids.to_s %> <%= test_case.name %> <%= test_case.problem_ids %> diff --git a/config/environment.rb b/config/environment.rb index 40704521..1c4c8f63 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,9 +1,5 @@ # Load the rails application require File.expand_path('../application', __FILE__) -require 'ext/string' -#longest length a string can be before it's truncated in index view -SHORTEN_LIMIT = 100 - #Initialize the rails application NZTrain::Application.initialize! diff --git a/lib/ext/string.rb b/lib/ext/string.rb deleted file mode 100644 index 5a853e13..00000000 --- a/lib/ext/string.rb +++ /dev/null @@ -1,9 +0,0 @@ -class String - def shorten - if self.size > SHORTEN_LIMIT - return self[0,SHORTEN_LIMIT] + "..." - end - - return self - end -end