ruby-nuggets 0.3.3.285 → 0.3.4.289
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/nuggets/object/singleton_class.rb +70 -2
- data/lib/nuggets/string/sub_with_md.rb +2 -2
- data/lib/nuggets/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
5
|
# language. #
|
6
6
|
# #
|
7
|
-
# Copyright (C) 2007 Jens Wille
|
7
|
+
# Copyright (C) 2007-2008 Jens Wille #
|
8
8
|
# #
|
9
9
|
# Authors: #
|
10
10
|
# Jens Wille <jens.wille@uni-koeln.de> #
|
@@ -41,10 +41,78 @@ class Object
|
|
41
41
|
alias_method :metaclass, :singleton_class
|
42
42
|
alias_method :uniclass, :singleton_class
|
43
43
|
|
44
|
+
# call-seq:
|
45
|
+
# object.singleton_object => anObject
|
46
|
+
#
|
47
|
+
# Returns the object of which _object_ is the singleton_class.
|
48
|
+
# Raises a TypeError if _object_ is not a singleton class.
|
49
|
+
def singleton_object
|
50
|
+
object = ObjectSpace.each_object(self) { |obj| break obj }
|
51
|
+
raise TypeError unless self.equal?(object.singleton_class)
|
52
|
+
object
|
53
|
+
rescue TypeError
|
54
|
+
raise TypeError, 'not a singleton class'
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :virtual_object, :singleton_object
|
58
|
+
alias_method :ghost_object, :singleton_object
|
59
|
+
alias_method :eigenobject, :singleton_object
|
60
|
+
alias_method :metaobject, :singleton_object
|
61
|
+
alias_method :uniobject, :singleton_object
|
62
|
+
|
63
|
+
# call-seq:
|
64
|
+
# object.singleton_class? => true or false
|
65
|
+
#
|
66
|
+
# Returns true if _object_ is a singleton_class
|
67
|
+
# (i.e., has a singleton_object), false otherwise.
|
68
|
+
def singleton_class?
|
69
|
+
singleton_object
|
70
|
+
true
|
71
|
+
rescue TypeError
|
72
|
+
false
|
73
|
+
end
|
74
|
+
|
75
|
+
alias_method :virtual_class?, :singleton_class?
|
76
|
+
alias_method :ghost_class?, :singleton_class?
|
77
|
+
alias_method :eigenclass?, :singleton_class?
|
78
|
+
alias_method :metaclass?, :singleton_class?
|
79
|
+
alias_method :uniclass?, :singleton_class?
|
80
|
+
|
44
81
|
end
|
45
82
|
|
46
83
|
if $0 == __FILE__
|
47
84
|
o = Object.new
|
48
85
|
p o
|
49
|
-
p o.singleton_class
|
86
|
+
p o.singleton_class?
|
87
|
+
|
88
|
+
begin
|
89
|
+
p o.singleton_object
|
90
|
+
rescue TypeError => err
|
91
|
+
warn err
|
92
|
+
end
|
93
|
+
|
94
|
+
s = o.singleton_class
|
95
|
+
p s
|
96
|
+
p s.singleton_class?
|
97
|
+
p s.singleton_object
|
98
|
+
|
99
|
+
o = [1, 2]
|
100
|
+
p o
|
101
|
+
|
102
|
+
s = o.singleton_class
|
103
|
+
p s
|
104
|
+
p s.singleton_class?
|
105
|
+
p s.singleton_object
|
106
|
+
|
107
|
+
p Class.new.singleton_class?
|
108
|
+
p Class.singleton_class?
|
109
|
+
|
110
|
+
c = Class.new
|
111
|
+
o = c.new
|
112
|
+
p o
|
113
|
+
p c.singleton_class?
|
114
|
+
|
115
|
+
p nil.singleton_class
|
116
|
+
p NilClass.singleton_class?
|
117
|
+
p NilClass.singleton_object # raises TypeError
|
50
118
|
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4.289
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-18 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|