diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-23 06:23:16 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-23 06:23:16 +0000 |
commit | b576fa8131cbfe772484709068132db49ffacb10 (patch) | |
tree | 00cf5faf7250638ff0f8df6ae073b61cedc9356a /lib/net/ftp.rb | |
parent | f245026a81117f62581dce71c85fc5533a4fb536 (diff) | |
download | ruby-b576fa8131cbfe772484709068132db49ffacb10.tar.gz |
* 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/net/ftp.rb')
-rw-r--r-- | lib/net/ftp.rb | 28 |
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 |