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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.3.3
5
+ This documentation refers to ruby-nuggets version 0.3.4
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -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
@@ -110,8 +110,8 @@ if $0 == __FILE__
110
110
  #p m
111
111
  begin
112
112
  "#{$1.gsub(/[ao]/, 'X')}#{$2}"
113
- rescue NoMethodError => e
114
- warn e
113
+ rescue NoMethodError => err
114
+ warn err
115
115
  end
116
116
  }
117
117
 
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 3
7
- TINY = 3
7
+ TINY = 4
8
8
 
9
9
  class << self
10
10
 
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.3.285
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-17 00:00:00 +02:00
12
+ date: 2008-09-18 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15