Sha256: 135aa65aa02c6579dfbeb51a9adb09ffe5f37a251232959cf467668f1a729b6f

Contents?: true

Size: 1.1 KB

Versions: 28

Compression:

Stored size: 1.1 KB

Contents

# -*- encoding: UTF-8 -*-
require 'pathname'

module CSD
  module Extensions
    module Core
      # This module comprises extensions to the Dir object.
      #
      module Dir
        
        # This method returns the names of all children-directories (i.e. first generation of descendants)
        # of a directory in either an +Array+, or in a block. It does the same thing as
        # +Pathname.children_directories+ but returns just the name and not the entire path to the children directories.
        #
        # ==== Examples
        #
        #  Dir.directories('/home/user')    # => ['Desktop', 'Documents', ...]
        #
        #  Dir.directories('/home/user') do |dir|
        #    puts dir
        #  end
        #
        def directories(path, &block)
          if block_given?
            ::Pathname.new(path).children_directories { |pathname| yield pathname.basename.to_s }
          else
            ::Pathname.new(path).children_directories.map { |pathname| pathname.basename.to_s }
          end
        end
        
      end
    end
  end
end

class Dir #:nodoc:
  extend CSD::Extensions::Core::Dir
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
csd-0.4.3 lib/csd/extensions/core/dir.rb
csd-0.4.2 lib/csd/extensions/core/dir.rb
csd-0.4.1 lib/csd/extensions/core/dir.rb
csd-0.4.0 lib/csd/extensions/core/dir.rb
csd-0.3.7 lib/csd/extensions/core/dir.rb
csd-0.3.6 lib/csd/extensions/core/dir.rb
csd-0.3.5 lib/csd/extensions/core/dir.rb
csd-0.3.4 lib/csd/extensions/core/dir.rb
csd-0.3.3 lib/csd/extensions/core/dir.rb
csd-0.3.2 lib/csd/extensions/core/dir.rb
csd-0.3.1 lib/csd/extensions/core/dir.rb
csd-0.3.0 lib/csd/extensions/core/dir.rb
csd-0.2.2 lib/csd/extensions/core/dir.rb
csd-0.2.1 lib/csd/extensions/core/dir.rb
csd-0.2.0 lib/csd/extensions/core/dir.rb
csd-0.1.18 lib/csd/extensions/core/dir.rb
csd-0.1.17 lib/csd/extensions/core/dir.rb
csd-0.1.16 lib/csd/extensions/core/dir.rb
csd-0.1.15 lib/csd/extensions/core/dir.rb
csd-0.1.14 lib/csd/extensions/core/dir.rb