Permalink
Browse files

add Pathname#move_to

  • Loading branch information...
1 parent cf0d4b4 commit d1d480141fa5ccc09cdae06e39f3d9fee52471d3 @quix committed Aug 9, 2009
Showing with 16 additions and 0 deletions.
  1. +5 −0 lib/quix/ext/pathname.rb
  2. +11 −0 test/pathname_test.rb
View
@@ -87,6 +87,11 @@ def copy_to(dest, preserve = false)
self.class.new(dest)
end
+ def move_to(dest)
+ rename(dest)
+ self.class.new(dest)
+ end
+
class << self
def join(*paths)
new File.join(*paths)
View
@@ -159,4 +159,15 @@ def test_copy_to
assert_equal contents, dest.read
assert_equal dest, result
end
+
+ def test_move_to
+ source, dest = %w[source dest].map { |f| Pathname(DATA_DIR) + f }
+ contents = "abab"
+ source.write(contents)
+ assert(!dest.exist?)
+ result = source.move_to(dest)
+ assert(!source.exist?)
+ assert_equal contents, dest.read
+ assert_equal dest, result
+ end
end

0 comments on commit d1d4801

Please sign in to comment.