ruby-nuggets 0.3.4.289 → 0.3.4.291

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/nuggets/object/singleton_class.rb +34 -4
  2. metadata +46 -47
  3. data/HEADER +0 -27
@@ -47,9 +47,18 @@ class Object
47
47
  # Returns the object of which _object_ is the singleton_class.
48
48
  # Raises a TypeError if _object_ is not a singleton class.
49
49
  def singleton_object
50
- object = ObjectSpace.each_object(self) { |obj| break obj }
51
- raise TypeError unless self.equal?(object.singleton_class)
52
- object
50
+ [true, false, nil].each { |obj|
51
+ return obj if self.equal?(obj.singleton_class)
52
+ }
53
+
54
+ # raises TypeError if neither class nor module
55
+ ObjectSpace.each_object(self) { |obj|
56
+ return obj if self.equal?(obj.singleton_class)
57
+ }
58
+
59
+ # if we got here it can't be a singleton class
60
+ # or its singleton object doesn't exist anymore
61
+ raise TypeError
53
62
  rescue TypeError
54
63
  raise TypeError, 'not a singleton class'
55
64
  end
@@ -96,6 +105,8 @@ if $0 == __FILE__
96
105
  p s.singleton_class?
97
106
  p s.singleton_object
98
107
 
108
+ ###
109
+
99
110
  o = [1, 2]
100
111
  p o
101
112
 
@@ -104,15 +115,34 @@ if $0 == __FILE__
104
115
  p s.singleton_class?
105
116
  p s.singleton_object
106
117
 
118
+ ###
119
+
107
120
  p Class.new.singleton_class?
108
121
  p Class.singleton_class?
109
122
 
123
+ ###
124
+
110
125
  c = Class.new
111
126
  o = c.new
112
127
  p o
113
128
  p c.singleton_class?
114
129
 
130
+ ###
131
+
115
132
  p nil.singleton_class
116
133
  p NilClass.singleton_class?
117
- p NilClass.singleton_object # raises TypeError
134
+ p NilClass.singleton_object
135
+
136
+ ###
137
+
138
+ class A; end
139
+ class B < A; end
140
+
141
+ a = A.singleton_class
142
+ b = B.singleton_class
143
+
144
+ p a
145
+ p a.singleton_object #=> A
146
+ p b
147
+ p b.singleton_object #=> B
118
148
  end
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.289
4
+ version: 0.3.4.291
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -25,73 +25,72 @@ extra_rdoc_files:
25
25
  - README
26
26
  files:
27
27
  - lib/nuggets.rb
28
- - lib/nuggets/integer/to_binary_s.rb
29
- - lib/nuggets/integer/factorial.rb
30
- - lib/nuggets/version.rb
31
- - lib/nuggets/object/metaclass.rb
32
- - lib/nuggets/object/singleton_class.rb
33
- - lib/nuggets/object/virtual_class.rb
34
- - lib/nuggets/object/ghost_class.rb
35
- - lib/nuggets/object/eigenclass.rb
36
- - lib/nuggets/object/blank.rb
37
- - lib/nuggets/object/msend.rb
38
- - lib/nuggets/object/uniclass.rb
39
- - lib/nuggets/enumerable/agrep.rb
40
- - lib/nuggets/enumerable/all_any_extended.rb
41
- - lib/nuggets/enumerable/minmax.rb
42
28
  - lib/nuggets/all.rb
43
- - lib/nuggets/string/sub_with_md.rb
29
+ - lib/nuggets/version.rb
30
+ - lib/nuggets/io/agrep.rb
31
+ - lib/nuggets/io/modes.rb
32
+ - lib/nuggets/file/which.rb
33
+ - lib/nuggets/integer/factorial.rb
34
+ - lib/nuggets/integer/to_binary_s.rb
35
+ - lib/nuggets/array/to_hash.rb
36
+ - lib/nuggets/array/shuffle.rb
37
+ - lib/nuggets/array/format.rb
38
+ - lib/nuggets/array/in_order.rb
39
+ - lib/nuggets/array/combination.rb
40
+ - lib/nuggets/array/flatten_once.rb
41
+ - lib/nuggets/array/rand.rb
42
+ - lib/nuggets/array/only.rb
43
+ - lib/nuggets/array/monotone.rb
44
+ - lib/nuggets/uri/exist.rb
45
+ - lib/nuggets/uri/content_type.rb
46
+ - lib/nuggets/proc/bind.rb
47
+ - lib/nuggets/string/word_wrap.rb
44
48
  - lib/nuggets/string/msub.rb
45
49
  - lib/nuggets/string/case.rb
50
+ - lib/nuggets/string/sub_with_md.rb
46
51
  - lib/nuggets/string/evaluate.rb
47
- - lib/nuggets/string/word_wrap.rb
48
52
  - lib/nuggets/string/nsub.rb
49
53
  - lib/nuggets/string/capitalize_first.rb
50
- - lib/nuggets/env/user_home.rb
51
- - lib/nuggets/env/user_encoding.rb
52
- - lib/nuggets/hash/at.rb
53
- - lib/nuggets/hash/only.rb
54
- - lib/nuggets/hash/in_order.rb
55
- - lib/nuggets/hash/insert.rb
56
- - lib/nuggets/proc/bind.rb
57
- - lib/nuggets/array/rand.rb
58
- - lib/nuggets/array/to_hash.rb
59
- - lib/nuggets/array/flatten_once.rb
60
- - lib/nuggets/array/only.rb
61
- - lib/nuggets/array/in_order.rb
62
- - lib/nuggets/array/shuffle.rb
63
- - lib/nuggets/array/monotone.rb
64
- - lib/nuggets/array/format.rb
65
- - lib/nuggets/array/combination.rb
66
- - lib/nuggets/numeric/between.rb
54
+ - lib/nuggets/object/blank.rb
55
+ - lib/nuggets/object/metaclass.rb
56
+ - lib/nuggets/object/uniclass.rb
57
+ - lib/nuggets/object/singleton_class.rb
58
+ - lib/nuggets/object/ghost_class.rb
59
+ - lib/nuggets/object/eigenclass.rb
60
+ - lib/nuggets/object/virtual_class.rb
61
+ - lib/nuggets/object/msend.rb
62
+ - lib/nuggets/numeric/limit.rb
67
63
  - lib/nuggets/numeric/duration.rb
64
+ - lib/nuggets/numeric/between.rb
68
65
  - lib/nuggets/numeric/signum.rb
69
- - lib/nuggets/numeric/limit.rb
70
66
  - lib/nuggets/numeric/to_multiple.rb
71
- - lib/nuggets/util/added_methods/init.rb
72
- - lib/nuggets/util/added_methods.rb
73
- - lib/nuggets/util/ansicolor2css.rb
74
- - lib/nuggets/util/content_type.rb
67
+ - lib/nuggets/env/user_home.rb
68
+ - lib/nuggets/env/user_encoding.rb
75
69
  - lib/nuggets/util/dotted_decimal.rb
76
70
  - lib/nuggets/util/i18n.rb
77
- - lib/nuggets/file/which.rb
78
- - lib/nuggets/uri/content_type.rb
79
- - lib/nuggets/uri/exist.rb
80
- - lib/nuggets/io/modes.rb
81
- - lib/nuggets/io/agrep.rb
71
+ - lib/nuggets/util/ansicolor2css.rb
72
+ - lib/nuggets/util/content_type.rb
73
+ - lib/nuggets/util/added_methods.rb
74
+ - lib/nuggets/util/added_methods/init.rb
75
+ - lib/nuggets/enumerable/minmax.rb
76
+ - lib/nuggets/enumerable/all_any_extended.rb
77
+ - lib/nuggets/enumerable/agrep.rb
78
+ - lib/nuggets/hash/in_order.rb
79
+ - lib/nuggets/hash/only.rb
80
+ - lib/nuggets/hash/at.rb
81
+ - lib/nuggets/hash/insert.rb
82
82
  - COPYING
83
- - HEADER
83
+ - Rakefile
84
84
  - README
85
85
  - ChangeLog
86
- - Rakefile
87
86
  has_rdoc: true
88
87
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
89
88
  post_install_message:
90
89
  rdoc_options:
91
90
  - --line-numbers
91
+ - --all
92
92
  - --main
93
93
  - README
94
- - --all
95
94
  - --inline-source
96
95
  - --title
97
96
  - ruby-nuggets Application documentation
data/HEADER DELETED
@@ -1,27 +0,0 @@
1
- #--
2
- ###############################################################################
3
- # #
4
- # A component of ruby-nuggets, some extensions to the Ruby programming #
5
- # language. #
6
- # #
7
- # Copyright (C) 2007-2008 Jens Wille #
8
- # #
9
- # Authors: #
10
- # Jens Wille <jens.wille@uni-koeln.de> #
11
- # #
12
- # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
- # under the terms of the GNU General Public License as published by the Free #
14
- # Software Foundation; either version 3 of the License, or (at your option) #
15
- # any later version. #
16
- # #
17
- # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
20
- # more details. #
21
- # #
22
- # You should have received a copy of the GNU General Public License along #
23
- # with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
- # #
25
- ###############################################################################
26
- #++
27
-