summaryrefslogtreecommitdiff
path: root/dir.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-18 13:59:21 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-06 22:22:25 +0900
commit310054b240a511f888ec5092eb32fed29e4109c9 (patch)
tree95902ef4c474be41d190d001fd8c9147808f173b /dir.rb
parenta58bbd6a512d95ca010d8bebae4fe590400c1413 (diff)
Moved `Dir.open` and `Dir#initialize` to dir.rb
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3006
Diffstat (limited to 'dir.rb')
-rw-r--r--dir.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/dir.rb b/dir.rb
new file mode 100644
index 0000000000..e383c0ea9f
--- /dev/null
+++ b/dir.rb
@@ -0,0 +1,37 @@
+class Dir
+ # Dir.open( string ) -> aDir
+ # Dir.open( string, encoding: enc ) -> aDir
+ # Dir.open( string ) {| aDir | block } -> anObject
+ # Dir.open( string, encoding: enc ) {| aDir | block } -> anObject
+ #
+ # The optional <i>encoding</i> keyword argument specifies the encoding of the directory.
+ # If not specified, the filesystem encoding is used.
+ #
+ # With no block, <code>open</code> is a synonym for Dir::new. If a
+ # block is present, it is passed <i>aDir</i> as a parameter. The
+ # directory is closed at the end of the block, and Dir::open returns
+ # the value of the block.
+ def self.open(name, encoding: nil, &block)
+ dir = __builtin_dir_s_open(name, encoding)
+ if block
+ begin
+ yield dir
+ ensure
+ __builtin_dir_s_close(dir)
+ end
+ else
+ dir
+ end
+ end
+
+ # Dir.new( string ) -> aDir
+ # Dir.new( string, encoding: enc ) -> aDir
+ #
+ # Returns a new directory object for the named directory.
+ #
+ # The optional <i>encoding</i> keyword argument specifies the encoding of the directory.
+ # If not specified, the filesystem encoding is used.
+ def initialize(name, encoding: nil)
+ __builtin_dir_initialize(name, encoding)
+ end
+end