summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-23 06:23:16 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-23 06:23:16 +0000
commit3eabc555cbec01b73be75f1d91d802bcd0c21b54 (patch)
tree00cf5faf7250638ff0f8df6ae073b61cedc9356a /lib
parent1d3c07633c1e85c9499c1dec2169bad9fa4ff9f1 (diff)
* lib/net/ftp.rb (gettextfile, getbinaryfile): use the safe
navigation operator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/ftp.rb28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 32eef46543..88d070f9a3 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -1,5 +1,4 @@
-#
-# -*- frozen_string_literal: true -*-
+# frozen_string_literal: true
#
# = net/ftp.rb - FTP Client Library
#
@@ -601,7 +600,8 @@ module Net
# chunks.
#
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
- blocksize = DEFAULT_BLOCKSIZE) # :yield: data
+ blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
+ f = nil
result = nil
if localfile
if @resume
@@ -615,15 +615,15 @@ module Net
result = String.new
end
begin
- f.binmode if localfile
+ f.?binmode
retrbinary("RETR #{remotefile}", blocksize, rest_offset) do |data|
- f.write(data) if localfile
- yield(data) if block_given?
- result.concat(data) if result
+ f.?write(data)
+ block.?(data)
+ result.?concat(data)
end
return result
ensure
- f.close if localfile
+ f.?close
end
end
@@ -634,7 +634,9 @@ module Net
# If a block is supplied, it is passed the retrieved data one
# line at a time.
#
- def gettextfile(remotefile, localfile = File.basename(remotefile)) # :yield: line
+ def gettextfile(remotefile, localfile = File.basename(remotefile),
+ &block) # :yield: line
+ f = nil
result = nil
if localfile
f = open(localfile, "w")
@@ -644,13 +646,13 @@ module Net
begin
retrlines("RETR #{remotefile}") do |line, newline|
l = newline ? line + "\n" : line
- f.print(l) if localfile
- yield(line, newline) if block_given?
- result.concat(l) if result
+ f.?print(l)
+ block.?(line, newline)
+ result.?concat(l)
end
return result
ensure
- f.close if localfile
+ f.?close
end
end