superclass_hash 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,6 +2,5 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - rbx
5
- - rbx-2.0
6
5
  - jruby
7
6
 
data/README.md CHANGED
@@ -17,7 +17,7 @@ end
17
17
  superhash = SuperclassHash.new
18
18
  superhash[A] = "a"
19
19
  superhash[A] # => "a"
20
- superhash[B] # => "b"
20
+ superhash[B] # => "a"
21
21
  ```
22
22
 
23
23
 
@@ -1,3 +1,3 @@
1
1
  class SuperclassHash
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,22 +1,27 @@
1
1
  class SuperclassHash
2
2
  def initialize()
3
- @hash = {}
3
+ @normal_hash = {}
4
+ @classes_hash = {}
4
5
  end
5
6
 
6
7
  def [](key)
7
8
  unless key.is_a? Class
8
- return @hash[key]
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 @hash[klass] if @hash.has_key?(klass)
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
- @hash[key] = value
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.1
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-11 00:00:00 Z
13
+ date: 2011-06-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec