Module: Monkey::Ext::Pathname

Defined in:
lib/monkey/ext/pathname.rb

Instance Method Summary collapse

Instance Method Details

#cased_pathPathname, NilClass

Returns Path with correct casing.

Returns:

  • (Pathname, NilClass)

    Path with correct casing.



8
9
10
11
12
13
# File 'lib/monkey/ext/pathname.rb', line 8

def cased_path
  return unless exist?
  return Dir.chdir(self) { Pathname(Dir.pwd) } if ::File.directory? path
  files = Dir.chdir(dirname) { Dir.entries('.').select { |f| f.downcase == basename.to_s.downcase } }
  dirname.cased_path.join(files.size == 1 ? files.first : basename)
end

#chdir(&block) ⇒ Object



15
16
17
# File 'lib/monkey/ext/pathname.rb', line 15

def chdir(&block)
  Dir.chdir(self.to_s, &block)
end

#open(mode = "r", &block) ⇒ Object



19
20
21
# File 'lib/monkey/ext/pathname.rb', line 19

def open(mode = "r", &block)
  File.open(self, mode, &block)
end