defined_hash 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -22,6 +22,23 @@ class DefinedHash < Hash
22
22
  end
23
23
  end
24
24
 
25
+ # Looks up a value from the hash
26
+ #
27
+ # @param name [Symbol,String] Property to return value of
28
+ #
29
+ # @return [Object] the value
30
+ #
31
+ # @api public
32
+ def [](name)
33
+ if Symbol === name
34
+ super(name)
35
+ elsif (self.class.property_names.include?(name.to_s))
36
+ super(name.to_s.to_sym)
37
+ else
38
+ nil
39
+ end
40
+ end
41
+
25
42
 
26
43
  # Assign a value to the hash
27
44
  #
@@ -49,6 +49,10 @@ BareTest.suite "DefinedHash" do
49
49
  assert "Doesn't have non-valid keys set" do
50
50
  @person.has_key?(:num) == false
51
51
  end
52
+
53
+ assert "Allows lookup via string, too" do
54
+ @person['page'] == 'bob'
55
+ end
52
56
  end
53
57
 
54
58
  suite "DefinedHash properties", :depends_on => :new do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defined_hash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Stott
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-05 00:00:00 +01:00
18
+ date: 2010-07-25 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency