superclass_hash 0.0.1 → 0.0.2
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.
- data/.travis.yml +0 -1
- data/README.md +1 -1
- data/lib/superclass_hash/version.rb +1 -1
- data/lib/superclass_hash.rb +10 -5
- metadata +2 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/superclass_hash.rb
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
class SuperclassHash
|
2
2
|
def initialize()
|
3
|
-
@
|
3
|
+
@normal_hash = {}
|
4
|
+
@classes_hash = {}
|
4
5
|
end
|
5
6
|
|
6
7
|
def [](key)
|
7
8
|
unless key.is_a? Class
|
8
|
-
return @
|
9
|
+
return @normal_hash[key]
|
9
10
|
else
|
10
11
|
ancestors = key.ancestors
|
11
|
-
ancestors = ancestors[0..ancestors.index(Object)] #Going only as far as you can via superclass method
|
12
|
+
ancestors = ancestors[0..ancestors.index(Object)].map { |klass| klass.to_s.to_sym } #Going only as far as you can via superclass method
|
12
13
|
ancestors.each do |klass|
|
13
|
-
return @
|
14
|
+
return @classes_hash[klass] if @classes_hash.has_key?(klass)
|
14
15
|
end
|
15
16
|
return nil
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def []=(key, value)
|
20
|
-
|
21
|
+
if key.is_a? Class
|
22
|
+
@classes_hash[key.to_s.to_sym] = value
|
23
|
+
else
|
24
|
+
@normal_hash[key] = value
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: superclass_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Piotr Jakubowski
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-14 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|