Project

General

Profile

rb_path_to_class.patch

tenderlovemaking (Aaron Patterson), 07/01/2010 07:00 AM

View differences:

test/ruby/test_marshal.rb
449 449
    o2 = Marshal.load(m)
450 450
    assert_equal(o1, o2)
451 451
  end
452
  
452

  
453
  class MyThing
454
    @defines  = []
455
    @missings = []
456
    @consts   = []
457
    class << self;
458
      attr_accessor :defines
459
      attr_accessor :missings
460
      attr_accessor :consts
461
    end
462

  
463
    def self.const_defined? sym
464
      @defines << sym
465
      true
466
    end
467

  
468
    def self.const_missing sym
469
      @missings << sym
470
      class_eval consts.pop
471
      const_get sym
472
    end
473
  end
474

  
475
  def test_call_const_defined?
476
    foo_definition = <<-eorb
477
      class Foo
478
        attr_reader :message
479
        def initialize message
480
          @message = message
481
        end
482
      end
483
    eorb
484
    MyThing.class_eval foo_definition
485
    str = Marshal.dump MyThing::Foo.new 'bara'
486
    assert_equal [:Foo], MyThing.defines
487

  
488
    MyThing.send(:remove_const, :Foo)
489
    MyThing.consts << foo_definition
490
    obj = Marshal.load(str)
491
    assert_instance_of MyThing::Foo, obj
492
    assert_equal 'bara', obj.message
493

  
494
    assert_equal [:Foo, :Foo], MyThing.defines
495
    assert_equal [:Foo], MyThing.missings
496
  end
453 497
end
variable.c
272 272
	    p += 2;
273 273
	    pbeg = p;
274 274
	}
275
	if (!rb_const_defined(c, id)) {
275
	if (!rb_funcall(c, rb_intern("const_defined?"), 1, ID2SYM(id))) {
276 276
	  undefined_class:
277 277
	    rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
278 278
	}