From c5b5c9b7758433c23d2984445a0421efe060e352 Mon Sep 17 00:00:00 2001 From: "Robert \"ar\" Gerus" Date: Thu, 23 May 2013 08:28:49 +0200 Subject: [PATCH] Simplify the code by using a ternary operator. --- up.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/up.rb b/up.rb index f14dcb4..83492cd 100755 --- a/up.rb +++ b/up.rb @@ -15,15 +15,11 @@ ARGV.each do |path| # add the dot here, so that if we get a file without dot, we don't have # to conditionally add the dot later on ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/) + # make sure ext isn't nil + ext = ext.nil? ? "" : ext content = open(path).read md5 = Digest::MD5.hexdigest(content) - # basically a glorified syntax sugar for (ext.nil? ? "" : ext) - begin - Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) - # we probably tried to add nil to a string ("ext" could possibly be nil) - rescue TypeError - Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5) - end + Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext) } end