/
type.rb
72 lines (61 loc) · 2.25 KB
/
type.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- encoding: us-ascii -*-
# The Type module provides facilities for accessing various "type" related
# data about an object, as well as providing type coercion methods. These
# facilities are independent of the object and thus are more robust in the
# face of ad hoc monkeypatching.
module Rubinius
module Type
# Performs a direct kind_of? check on the object bypassing any method
# overrides.
def self.object_kind_of?(obj, cls)
Rubinius.primitive :vm_object_kind_of
raise PrimitiveFailure, "Rubinius::Type.object_kind_of? primitive failed"
end
def self.object_class(obj)
Rubinius.primitive :vm_object_class
raise PrimitiveFailure, "Rubinius::Type.object_class primitive failed"
end
def self.object_singleton_class(obj)
Rubinius.primitive :vm_object_singleton_class
raise TypeError, "no singleton class available for a #{Type.object_class(obj)}"
end
def self.singleton_class_object(mod)
Rubinius.primitive :vm_singleton_class_object
raise PrimitiveFailure, "Rubinius::Type.singleton_class_object primitive failed"
end
def self.object_respond_to?(obj, name)
Rubinius.primitive :vm_object_respond_to
raise PrimitiveFailure, "Rubinius::Type.object_respond_to? primitive failed"
end
def self.object_equal(a, b)
Rubinius.primitive :vm_object_equal
raise PrimitiveFailure, "Rubinius::Type.object_equal primitive failed"
end
def self.module_name(mod)
Rubinius.primitive :vm_get_module_name
raise PrimitiveFailure, "Rubinius::Type.module_name primitive failed"
end
def self.module_inspect(mod)
sc = singleton_class_object mod
if sc
case sc
when Class, Module
name = "#<Class:#{module_inspect(sc)}>"
else
cls = object_class sc
name = "#<Class:#<#{module_name(cls)}:0x#{sc.object_id.to_s(16)}>>"
end
else
name = module_name mod
if !name or name == ""
name = "#<#{object_class(mod)}:0x#{mod.object_id.to_s(16)}>"
end
end
name
end
def self.set_module_name(mod, name, under)
Rubinius.primitive :vm_set_module_name
raise PrimitiveFailure, "Rubinius::Type.set_module_name primitive failed"
end
end
end