Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ext/1.9/dir.rb: Dir.glob should accept Pathnames

  • Loading branch information...
commit 7b523c541fa47ac55e64450576ea5f7531056fa0 1 parent f189dbc
@quix authored
Showing with 45 additions and 0 deletions.
  1. +25 −0 lib/quix/ext/1.9/dir.rb
  2. +2 −0  lib/quix/ext/dir.rb
  3. +18 −0 test/test_dir.rb
View
25 lib/quix/ext/1.9/dir.rb
@@ -0,0 +1,25 @@
+
+class Dir
+ class << self
+ alias_method :quix_original_glob, :glob
+ def glob(pattern, *args, &block)
+ result = (
+ case pattern
+ when Enumerable
+ begin
+ pattern.map { |t| t.to_path }
+ rescue
+ pattern.map { |t| t.to_s }
+ end
+ else
+ begin
+ pattern.to_path
+ rescue
+ pattern.to_s
+ end
+ end
+ )
+ quix_original_glob(result, *args, &block)
+ end
+ end
+end
View
2  lib/quix/ext/dir.rb
@@ -1,4 +1,6 @@
+require 'quix/ext/1.9/dir' if RUBY_VERSION >= "1.9"
+
class Dir
class << self
def empty?(dir)
View
18 test/test_dir.rb
@@ -1,6 +1,7 @@
require File.dirname(__FILE__) + "/common"
require 'quix/ext/dir'
+require 'quix/ext/pathname'
class TestDir < Test::Unit::TestCase
include FileUtils
@@ -11,4 +12,21 @@ def test_dir
touch "#{DATA_DIR}/t"
assert_equal(false, Dir.empty?(DATA_DIR))
end
+
+ def test_glob
+ file = "#{DATA_DIR}/a"
+ touch file
+
+ files = Dir.glob("#{DATA_DIR}/*")
+ assert_equal [file], files
+
+ files = Dir.glob(Pathname("#{DATA_DIR}/*"))
+ assert_equal [file], files
+
+ files = Dir.glob(["#{DATA_DIR}/*"])
+ assert_equal [file], files
+
+ files = Dir.glob([Pathname("#{DATA_DIR}/*")])
+ assert_equal [file], files
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.