mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
4 changed files with 34 additions and 10 deletions
|
@ -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>
|
||||
|
||||
* 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.
|
||||
|
||||
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>
|
||||
|
||||
* eval.c (thread_mark): mark thread group. [ruby-dev:25020]
|
||||
|
|
2
eval.c
2
eval.c
|
@ -2477,7 +2477,7 @@ call_trace_func(event, node, self, id, klass)
|
|||
srcfile,
|
||||
INT2FIX(ruby_sourceline),
|
||||
id?ID2SYM(id):Qnil,
|
||||
self?rb_f_binding(self):Qnil,
|
||||
self ? rb_f_binding(self) : Qnil,
|
||||
klass?klass:Qnil),
|
||||
Qundef, 0);
|
||||
}
|
||||
|
|
4
io.c
4
io.c
|
@ -4094,9 +4094,7 @@ rb_file_initialize(argc, argv, io)
|
|||
VALUE io;
|
||||
{
|
||||
if (RFILE(io)->fptr) {
|
||||
rb_io_close_m(io);
|
||||
free(RFILE(io)->fptr);
|
||||
RFILE(io)->fptr = 0;
|
||||
rb_raise(rb_eRuntimeError, "reinitializing File");
|
||||
}
|
||||
if (0 < argc && argc < 3) {
|
||||
VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
|
||||
|
|
|
@ -47,10 +47,8 @@ class OpenStruct
|
|||
@table = {}
|
||||
if 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
|
||||
new_ostruct_member(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -61,6 +59,27 @@ class OpenStruct
|
|||
@table = @table.dup
|
||||
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:
|
||||
mname = mid.id2name
|
||||
len = args.length
|
||||
|
@ -72,10 +91,8 @@ class OpenStruct
|
|||
raise TypeError, "can't modify frozen #{self.class}", caller(1)
|
||||
end
|
||||
mname.chop!
|
||||
if $DEBUG and self.respond_to?(mname, true)
|
||||
raise NameError, "already existing member #{mname}", caller(1)
|
||||
end
|
||||
@table[mname.intern] = args[0]
|
||||
self.new_ostruct_member(mname)
|
||||
elsif len == 0
|
||||
@table[mid]
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue