* io.c (rb_file_initialize): [ruby-dev:25032]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dd1510eddc
commit
5847fadf7b
@ -1,3 +1,7 @@
|
|||||||
|
Fri Dec 3 00:11:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_file_initialize): [ruby-dev:25032]
|
||||||
|
|
||||||
Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_protect): prevent continuations created inside from being
|
* eval.c (rb_protect): prevent continuations created inside from being
|
||||||
@ -10,6 +14,11 @@ Thu Dec 2 10:45:02 2004 Shugo Maeda <shugo@ruby-lang.org>
|
|||||||
|
|
||||||
* test/readline/test_readline.rb: fix for NetBSD.
|
* test/readline/test_readline.rb: fix for NetBSD.
|
||||||
|
|
||||||
|
Thu Dec 2 09:57:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/ostruct.rb (OpenStruct::Marshaler): OpenStruct can be
|
||||||
|
marshaled again. [ruby-core:03862]
|
||||||
|
|
||||||
Thu Dec 2 09:30:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Dec 2 09:30:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (thread_mark): mark thread group. [ruby-dev:25020]
|
* eval.c (thread_mark): mark thread group. [ruby-dev:25020]
|
||||||
|
4
io.c
4
io.c
@ -4094,9 +4094,7 @@ rb_file_initialize(argc, argv, io)
|
|||||||
VALUE io;
|
VALUE io;
|
||||||
{
|
{
|
||||||
if (RFILE(io)->fptr) {
|
if (RFILE(io)->fptr) {
|
||||||
rb_io_close_m(io);
|
rb_raise(rb_eRuntimeError, "reinitializing File");
|
||||||
free(RFILE(io)->fptr);
|
|
||||||
RFILE(io)->fptr = 0;
|
|
||||||
}
|
}
|
||||||
if (0 < argc && argc < 3) {
|
if (0 < argc && argc < 3) {
|
||||||
VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
|
VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
|
||||||
|
@ -47,10 +47,8 @@ class OpenStruct
|
|||||||
@table = {}
|
@table = {}
|
||||||
if hash
|
if hash
|
||||||
for k,v in hash
|
for k,v in hash
|
||||||
if $DEBUG and self.respond_to?(k, true)
|
|
||||||
raise NameError, "already existing member #{k}", caller(2)
|
|
||||||
end
|
|
||||||
@table[k.to_sym] = v
|
@table[k.to_sym] = v
|
||||||
|
new_ostruct_member(k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -61,6 +59,27 @@ class OpenStruct
|
|||||||
@table = @table.dup
|
@table = @table.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Marshaler
|
||||||
|
def marshal_dump
|
||||||
|
table = @table
|
||||||
|
OpenStruct.new.instance_eval{@table=table; self}
|
||||||
|
end
|
||||||
|
def marshal_load(x)
|
||||||
|
@table = x.instance_variable_get("@table")
|
||||||
|
@table.each_key{|key| new_ostruct_member(key)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_ostruct_member(name)
|
||||||
|
unless self.respond_to?(name)
|
||||||
|
self.instance_eval %{
|
||||||
|
extend OpenStruct::Marshaler
|
||||||
|
def #{name}; @table[:#{name}]; end
|
||||||
|
def #{name}=(x); @table[:#{name}] = x; end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def method_missing(mid, *args) # :nodoc:
|
def method_missing(mid, *args) # :nodoc:
|
||||||
mname = mid.id2name
|
mname = mid.id2name
|
||||||
len = args.length
|
len = args.length
|
||||||
@ -72,10 +91,8 @@ class OpenStruct
|
|||||||
raise TypeError, "can't modify frozen #{self.class}", caller(1)
|
raise TypeError, "can't modify frozen #{self.class}", caller(1)
|
||||||
end
|
end
|
||||||
mname.chop!
|
mname.chop!
|
||||||
if $DEBUG and self.respond_to?(mname, true)
|
|
||||||
raise NameError, "already existing member #{mname}", caller(1)
|
|
||||||
end
|
|
||||||
@table[mname.intern] = args[0]
|
@table[mname.intern] = args[0]
|
||||||
|
self.new_ostruct_member(mname)
|
||||||
elsif len == 0
|
elsif len == 0
|
||||||
@table[mid]
|
@table[mid]
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user