y_support 2.0.13 → 2.0.14
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.
- checksums.yaml +4 -4
- data/lib/y_support/name_magic.rb +10 -5
- data/lib/y_support/version.rb +1 -1
- data/test/name_magic_test.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2417e6453a390dd0001a7add38638b69989f3da
|
4
|
+
data.tar.gz: 7c430e880d23c375a741572d7758c0dee3edb19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4ad637111c552d83e59345ee193b6bb15d9dc1d22e2ef31ca2c38500c70370f05a4a27e64c103b7308a315bc1565c4c6955d38373a37e5945f3729b70ff4d4
|
7
|
+
data.tar.gz: 6b158e5be9d2652019df69e9b2ee3b3ae0d380283d2d15cfda935c13cf174c6a55370264f9d4eb6006dba3720e8980f20d2670b0f9d7d471258a1cc7470008a1
|
data/lib/y_support/name_magic.rb
CHANGED
@@ -158,14 +158,20 @@ module NameMagic
|
|
158
158
|
self
|
159
159
|
end
|
160
160
|
|
161
|
-
# Makes the class use the namespace supplied as
|
162
|
-
# is given, the class/module itself will be made its own namespace. Returns
|
163
|
-
# self.
|
161
|
+
# Makes the class use the namespace supplied as an argument.
|
164
162
|
#
|
165
|
-
def namespace
|
163
|
+
def namespace= namespc
|
166
164
|
namespc.extend ::NameMagic::NamespaceMethods unless namespc == self
|
167
165
|
tap { define_singleton_method :namespace do namespc end }
|
168
166
|
end
|
167
|
+
|
168
|
+
# Makes the class/module use itself as a namespace. (Useful eg. with
|
169
|
+
# parametrized subclassing to tell the subclasses to maintain each their
|
170
|
+
# own namespaces.)
|
171
|
+
#
|
172
|
+
def namespace!
|
173
|
+
self.namespace = self
|
174
|
+
end
|
169
175
|
|
170
176
|
# Returns the instance identified by the argument. NameError is raised, if
|
171
177
|
# the argument does not identify an instance. (It can be an instance name
|
@@ -187,7 +193,6 @@ module NameMagic
|
|
187
193
|
end or raise NameError, "No instance #{arg} in #{namespace}."
|
188
194
|
end
|
189
195
|
|
190
|
-
|
191
196
|
# The method will search all the modules in the the object space for
|
192
197
|
# receiver class objects assigned to constants, and name these instances
|
193
198
|
# accordingly. Number of the remaining nameless instances is returned.
|
data/lib/y_support/version.rb
CHANGED
data/test/name_magic_test.rb
CHANGED
@@ -53,5 +53,17 @@ describe NameMagic do
|
|
53
53
|
@reporter.name_get.must_equal "Name get closure called on UFO"
|
54
54
|
Elaine = @ç.new
|
55
55
|
Elaine.name.must_equal :Elaine
|
56
|
+
m = Module.new
|
57
|
+
XXX = m
|
58
|
+
@ç.namespace = XXX
|
59
|
+
@ç.namespace.must_equal m
|
60
|
+
Rover = @ç.new
|
61
|
+
@ç.const_magic
|
62
|
+
XXX::Rover.must_be_kind_of @ç
|
63
|
+
@ç.namespace!
|
64
|
+
Spot = @ç.new
|
65
|
+
@ç.const_magic
|
66
|
+
-> { XXX::Spot }.must_raise NameError
|
67
|
+
@ç.const_get( :Spot ).must_be_kind_of @ç
|
56
68
|
end
|
57
69
|
end
|