[macruby-changes] [MacRuby/MacRuby] 6c5fdc: IO.sysopen will accept an Object which has to_path...

noreply at github.com noreply at github.com
Mon May 16 00:38:44 PDT 2011


Branch: refs/heads/master
Home:   https://github.com/MacRuby/MacRuby

Commit: 6c5fdc98b345dfea2ddc1efe71148e2ba9022889
    https://github.com/MacRuby/MacRuby/commit/6c5fdc98b345dfea2ddc1efe71148e2ba9022889
Author: Watson <watson1978 at gmail.com>
Date:   2011-05-16 (Mon, 16 May 2011)

Changed paths:
  M io.c

Log Message:
-----------
IO.sysopen will accept an Object which has to_path method as file path.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

obj = Object.new
def  obj.to_path; "/tmp/foo"; end

fd = IO.sysopen(obj, "w")
io = IO.open(fd)
assert_match(/#<IO:fd #{fd}>/, io.inspect)

puts :ok
}}}


Commit: 7d56792f63d754d85fe383d7e7b1d68a5c9fccf0
    https://github.com/MacRuby/MacRuby/commit/7d56792f63d754d85fe383d7e7b1d68a5c9fccf0
Author: Watson <watson1978 at gmail.com>
Date:   2011-05-16 (Mon, 16 May 2011)

Changed paths:
  M io.c

Log Message:
-----------
File.open will accept an Object which has to_int or to_str method as open mode.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

mode_i = Object.new
def mode_i.to_int; IO::WRONLY|IO::CREAT|IO::TRUNC; end

f = File.open("/tmp/foo", mode_i)
assert_equal("#<File:/tmp/foo>", f.inspect)
f.close

mode_s = Object.new
def mode_s.to_str; "w"; end

f = File.open("/tmp/bar", mode_s)
assert_equal("#<File:/tmp/bar>", f.inspect)

puts :ok
}}}


Commit: 6882cd789087b9eb6e195e310a60e15e47800ea2
    https://github.com/MacRuby/MacRuby/commit/6882cd789087b9eb6e195e310a60e15e47800ea2
Author: Watson <watson1978 at gmail.com>
Date:   2011-05-16 (Mon, 16 May 2011)

Changed paths:
  M io.c

Log Message:
-----------
Implements the IO.binread

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

File.open("/tmp/foo", "w") {|f|
  f.write "foo\nbar\nbaz\n012345"
}

assert_equal("foo\nbar\nbaz\n012345", IO.binread("/tmp/foo"))
assert_equal("foo\nb", IO.binread("/tmp/foo", 5))
assert_equal("ar", IO.binread("/tmp/foo", 2, 5))

puts :ok
}}}


Commit: 6af03f51ba402491d4333c4fbe3b12171a4e82c4
    https://github.com/MacRuby/MacRuby/commit/6af03f51ba402491d4333c4fbe3b12171a4e82c4
Author: Watson <watson1978 at gmail.com>
Date:   2011-05-16 (Mon, 16 May 2011)

Changed paths:
  M io.c

Log Message:
-----------
Kernel#open will accept an Object which has to_open method.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

o = Object.new
def o.to_open; self; end
assert_equal(o, open(o))

o2 = nil
open(o) do |f|
  o2 = f
end
assert_equal(o, o2)

puts :ok
}}}


Compare: https://github.com/MacRuby/MacRuby/compare/8d7fdfe...6af03f5


More information about the macruby-changes mailing list