y_support 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e5d5e63041346d0129e1ddbd75122c7e878cf92
4
- data.tar.gz: b7b2e14abfcac7f070cb3b4a0a264c2086f73bd1
3
+ metadata.gz: f967a550973926b2ab9ad6d5df847b29bad6a27d
4
+ data.tar.gz: 95ad37737fff575a53db65f9da4ed829d58f8ccb
5
5
  SHA512:
6
- metadata.gz: 771724a6d0d9c63655ef996443d1861f3c0cb59d94516393f3d7689669c860f6889fa4bf0cdb1673dda77fdfb6bb2498483cdce8b39e97db55ca8727c827c4e1
7
- data.tar.gz: 0f4502be79ac39d5415ee965dab65419b58cb5b6dad5d76f646bc1037ba9ae01a65e9c0ad615d9bf584683e70ceb0c7ee21ad939d34842b0b436ad977759eb22
6
+ metadata.gz: ce8b98cfbc46430bde6d324045772e34ded7791a4fcb8470b71ebd9f01825bcc48f68afcf0670f28b70c728201b48acef96ac72cb4f2bbee8031f9da2200880d
7
+ data.tar.gz: 6709e08ebd27dcdd0202239ab4a00197bd2978353b7b6f1b2894dd6832ac18ac8288d4a7a5ceb6e0787561961d8462b4ecd316150ddbee7c9927f1af93af97ed
@@ -135,7 +135,7 @@ module NameMagic
135
135
  #
136
136
  def instances
137
137
  const_magic
138
- __instances__.keys
138
+ __instances__.keys.select { |i| i.kind_of? self }
139
139
  end
140
140
 
141
141
  # Presents an array of all the instance names (disregarding anonymous
@@ -148,14 +148,14 @@ module NameMagic
148
148
  # Presents class-owned @instances without const_magic.
149
149
  #
150
150
  def __instances__
151
- namespace.instance_variable_get( :@instances ) or
151
+ namespace.instance_variable_get( :@instances ) ||
152
152
  namespace.instance_variable_set( :@instances, {} )
153
153
  end
154
154
 
155
155
  # Presents class-owned @avid_instances (no const_magic).
156
156
  #
157
157
  def __avid_instances__
158
- namespace.instance_variable_get( :@avid_instances ) or
158
+ namespace.instance_variable_get( :@avid_instances ) ||
159
159
  namespace.instance_variable_set( :@avid_instances, [] )
160
160
  end
161
161
 
@@ -167,26 +167,23 @@ module NameMagic
167
167
  self
168
168
  end
169
169
 
170
- # Returns an instance identiified by the argument. NameError is raised, if
170
+ # Returns the instance identified by the argument. NameError is raised, if
171
171
  # the argument does not identify an instance. (It can be an instance name
172
- # as string, symbol, or an instance itself, in which case it is merely
173
- # returned without changes.)
172
+ # as string, symbol, or an instance itself, in which case, the instance in
173
+ # question is merely returned without changes.)
174
174
  #
175
175
  def instance arg
176
- const_magic
177
- # Reject nil argument. (In @instances hash, nameless instances are given
178
- # name nil, so 'nil' cannot be a real name.)
179
- fail TypeError, "'nil' is not a valid argument type for " +
180
- "NameMagic#instance method!" if arg.nil?
176
+ # In @instances hash, name 'nil' means nameless!
177
+ msg = "'nil' is not a valid argument type for NameMagic#instance method!"
178
+ fail TypeError, msg if arg.nil?
181
179
  # if the argument is an actual instance, just return it
182
- return arg if __instances__.keys.include? arg
183
- # otherwise, treat it as name
184
- r = begin
185
- __instances__.rassoc( arg ) || __instances__.rassoc( arg.to_sym )
186
- rescue NoMethodError
187
- end or
188
- raise NameError, "No instance #{arg} in #{namespace}."
189
- return r[0]
180
+ ii = instances
181
+ return arg if ii.include? arg
182
+ # otherwise, assume arg is a name
183
+ begin
184
+ ii.find { |i| i.name == arg || i.name == arg.to_sym }
185
+ rescue NoMethodError
186
+ end or raise NameError, "No instance #{arg} in #{namespace}."
190
187
  end
191
188
 
192
189
 
@@ -1,3 +1,3 @@
1
1
  module YSupport
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport