From 310054b240a511f888ec5092eb32fed29e4109c9 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 18 Jan 2020 13:59:21 +0900 Subject: Moved `Dir.open` and `Dir#initialize` to dir.rb --- dir.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dir.rb (limited to 'dir.rb') 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 encoding keyword argument specifies the encoding of the directory. + # If not specified, the filesystem encoding is used. + # + # With no block, open is a synonym for Dir::new. If a + # block is present, it is passed aDir 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 encoding 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 -- cgit v1.2.3