0001-ext-pathname-lib-pathname.rb-add-Pathname-write-and-.patch

Benoit Daloze, 01/14/2013 06:01 AM

Download (2.17 KB)

View differences:

ChangeLog
1
Mon Jan 14 05:56:27 2013  Benoit Daloze  <eregontp@gmail.com>
2

  
3
	* ext/pathname/lib/pathname.rb: add Pathname#write and #binwrite.
4

  
5
	* test/pathname/test_pathname.rb: add tests.
6

  
1 7
Sun Jan 13 16:45:00 2013  Zachary Scott <zachary@zacharyscott.net>
2 8

  
3 9
	* ext/psych/yaml/scanner.c: Fix typos, patch by James Dabbs
ext/pathname/lib/pathname.rb
516 516
      Pathname.new(File.join(*relpath_names))
517 517
    end
518 518
  end
519

  
520
  # Writes +contents+ to the file.
521
  #
522
  # See IO.write.
523
  def write(contents, *args)
524
    IO.write(@path, contents, *args)
525
  end
526

  
527
  # Writes +contents+ to the file, opening it in binary mode.
528
  #
529
  # See IO.binwrite.
530
  def binwrite(contents, *args)
531
    IO.binwrite(@path, contents, *args)
532
  end
519 533
end
520 534

  
521 535

  
test/pathname/test_pathname.rb
716 716
    }
717 717
  end
718 718

  
719
  def test_write
720
    with_tmpchdir('rubytest-pathname') {|dir|
721
      path = Pathname("a")
722
      path.write "abc"
723
      assert_equal("abc", path.read)
724
    }
725
  end
726

  
727
  def test_binwrite
728
    with_tmpchdir('rubytest-pathname') {|dir|
729
      path = Pathname("a")
730
      path.binwrite "abc\x80"
731
      assert_equal("abc\x80".b, path.binread)
732
    }
733
  end
734

  
719 735
  def test_sysopen
720 736
    with_tmpchdir('rubytest-pathname') {|dir|
721 737
      open("a", "w") {|f| f.write "abc" }
722
-