summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-19 17:26:04 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-19 17:26:04 +0000
commit6e6ca326e8d0a46bc3a5b45a78a09b932b861657 (patch)
tree1d5c45896c45281a422b3224a0d9f5994126d796 /lib
parente081eda18f390122b7be574573f96f2d2d663837 (diff)
downloadruby-6e6ca326e8d0a46bc3a5b45a78a09b932b861657.tar.gz
ruby-6e6ca326e8d0a46bc3a5b45a78a09b932b861657.tar.xz
ruby-6e6ca326e8d0a46bc3a5b45a78a09b932b861657.zip
* string.c (rb_str_match2): add warning to "~string".
[ruby-list:37751] * lib/net/ftp.rb (Net::FTP::open): takes block. suggested by Gavin Sinclair in [ruby-core:01237]. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/ftp.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index b34c648bf..6f5f84807 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -87,8 +87,20 @@ module Net
#
# A synonym for +FTP.new+, but with a mandatory host parameter.
#
+ # If a block is given, it is passed the +FTP+ object, which will be closed
+ # when the block finishes, or when an exception is raised.
+ #
def FTP.open(host, user = nil, passwd = nil, acct = nil)
- new(host, user, passwd, acct)
+ if block_given?
+ ftp = new(host, user, passwd, acct)
+ begin
+ yield ftp
+ ensure
+ ftp.close
+ end
+ else
+ new(host, user, passwd, acct)
+ end
end
#