~tim/natalie

ref: 8e9e487dd5b7be3438aadcad6503e8b46a72e0b0 natalie/test/natalie/singleton_class_test.rb -rw-r--r-- 1.1 KiB
8e9e487dTim Morgan Store method name and owner on the Method object 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative '../spec_helper'

class Foo
end

class Bar < Foo
end

describe 'singleton_class' do
  it 'has the correct hierarchy' do
    klass = Bar.singleton_class
    klass.inspect.should == '#<Class:Bar>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:Foo>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:Object>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:BasicObject>'
    klass = klass.superclass
    klass.should == Class
    klass = klass.superclass
    klass.should == Module
    klass = klass.superclass
    klass.should == Object
    klass = klass.superclass
    klass.should == BasicObject
    klass = klass.superclass
    klass.should == nil

    klass = Class.singleton_class
    klass.inspect.should == '#<Class:Class>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:Module>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:Object>'
    klass = klass.superclass
    klass.inspect.should == '#<Class:BasicObject>'
    klass = klass.superclass
    klass.should == Class
  end
end