Feature #3511 » rb_path_to_class.patch
test/ruby/test_marshal.rb | ||
---|---|---|
o2 = Marshal.load(m)
|
||
assert_equal(o1, o2)
|
||
end
|
||
|
||
class MyThing
|
||
@defines = []
|
||
@missings = []
|
||
@consts = []
|
||
class << self;
|
||
attr_accessor :defines
|
||
attr_accessor :missings
|
||
attr_accessor :consts
|
||
end
|
||
def self.const_defined? sym
|
||
@defines << sym
|
||
true
|
||
end
|
||
def self.const_missing sym
|
||
@missings << sym
|
||
class_eval consts.pop
|
||
const_get sym
|
||
end
|
||
end
|
||
def test_call_const_defined?
|
||
foo_definition = <<-eorb
|
||
class Foo
|
||
attr_reader :message
|
||
def initialize message
|
||
@message = message
|
||
end
|
||
end
|
||
eorb
|
||
MyThing.class_eval foo_definition
|
||
str = Marshal.dump MyThing::Foo.new 'bara'
|
||
assert_equal [:Foo], MyThing.defines
|
||
MyThing.send(:remove_const, :Foo)
|
||
MyThing.consts << foo_definition
|
||
obj = Marshal.load(str)
|
||
assert_instance_of MyThing::Foo, obj
|
||
assert_equal 'bara', obj.message
|
||
assert_equal [:Foo, :Foo], MyThing.defines
|
||
assert_equal [:Foo], MyThing.missings
|
||
end
|
||
end
|
variable.c | ||
---|---|---|
p += 2;
|
||
pbeg = p;
|
||
}
|
||
if (!rb_const_defined(c, id)) {
|
||
if (!rb_funcall(c, rb_intern("const_defined?"), 1, ID2SYM(id))) {
|
||
undefined_class:
|
||
rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
|
||
}
|